SearchView which overlaps ActionBar - android

Instead of using an ActionLayout to replace the ActionBar when pressed a MenuItem. I want that ActionLayout to overlap on the ActionBar.
Since most of the applications use this behavior I thought its the standard SearchView widget.
And since my application is for API 10 and more, i couldn't use SearchView, hence used latest ActionBarSherlock library(4.2.0), where Jake added SearchView.
The problem is, even here its like replacing the initial menu items with the ActionViewClass.
The reason i want the ActionLayout to overlap but not replace the ActionBar is, I need to have 3 MenuItems in the ActionBar and if i keep all of them as
android:showAsAction="always|collapseActionView"
they are even visible when ActionLayout is shown, which gives little width for the ActionLayout
if i am using
android:showAsAction="ifRoom"
the last icon is missing. Only 2 icons are visible.
Thank You

If you are having physical menu button (e.g. Nexus S) in your device then the dot line will not show. When you press the Menu button it’ll show up.
You may use something as this Use android:showAsAction="never" to force an action item into the overflow.

Related

Application Name in toolbar hide when 5 item added in it , how to show app name always in toolbar?

I have added 5 items on toolbar and when I reviewed in medium and small phones then application name is not visible.
How can I set application name to show always and reduce toolbar's items size according to available devices?
If by toolbar you are referring to the app's ActionBar, then what you are looking for is an overflow menu (that three vertical dots option you see on the top right corner of apps). Reading Android's docs on menus might help.
Basically you want to make sure some, or all of your items have the android:showAsAction property set to never or ifRoom as follows:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action1"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:title="#string/action1_string"/>
<item
android:id="#+id/action2"
android:orderInCategory="2"
android:showAsAction="never"
android:title="#string/action2_string"/>
</menu>
The key here is the android:showAsAction property, which allows you to specify when should an item be added to the bar and when it should be added to the overflow menu. Possible values are:
ifRoom: Only place this item in the app bar if there is room for it. If there is not room for all the items marked "ifRoom", the items with the lowest orderInCategory values are displayed as actions, and the remaining items are displayed in the overflow menu.
withText: Also include the title text (defined by android:title) with the action item. You can include this value along with one of the others as a flag set, by separating them with a pipe |. E.g. : android:showAsAction="ifRoom|withText"
always: Always place this item in the app bar. Avoid using this unless it's critical that the item always appear in the action bar. Setting multiple items to always appear as action items can result in them overlapping with other UI in the app bar.
never: Never place this item in the app bar. Instead, list the item in the app bar's overflow menu.
collapseActionView: The action view associated with this action item is collapsible. API 14 onwards.
Source.

setShowsAsAction not working below API 11

This is the code I used to remove a MenuItem:
af.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
However, setShowsAsAction requires minimum API 11 so it crashes on GingerBread. I can use af.setVisible(false); to get the code to work on GingerBread. What are the differences between the two? Is it the same thing?
Use the v7 support library as followed:
MenuItem menuItem = menu.add(....);
MenuItemCompat.setShowAsAction(menuItem , MenuItemCompat.SHOW_AS_ACTION_NEVER);
1. af.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
This will cause the MenuItem to be hidden fro the ActionBar. However it will be visible in the OverFlow Menu.
2. af.setVisible(false);
This will hide the MenuItem completely from the ActionBar and the Overflow Menu as well.
The difference might be when you set showAsAction to never, your menu item is still accessible with menu hardware or overflow button in ActionBar whereas when you use set visible method, your menu item is not displayed, even if you press the menu.
According to the reference, setVisible(boolean visible):
Sets the visibility of the MenuItem. If true the item will be visible; if false it is hidden (added in API 1)
And showAsAction method:
Sets how this item should display in the presence of an Action Bar (added in API 11)
As you can read, the mostly difference is showAsAction="never" is related to the ActionBar and hiding on it but still showing in overflow menu whereas setVisible since API 1 doesn't care about overflow menu and ActionBar: set to false, it litteraly hide your menu item.

showAsAction "always" does not work for item in android

In my android application, I have an item in the menu, and I want the item display all the time with the icon and the text, this is the setting:
<item
android:id="#+id/menu_submit_back_tomap"
android:title="#string/menu_back_tomap"
android:icon="#drawable/ic_action_back"
android:showAsAction="always|withText"/>
However I can only see the icon, the text is not displayed, what's the problem?
BTW, this is the only item in the menu.
It depend on available space if there will be space to display text it will be displayed if not then only icon will be displayed.
" The "withText" value is a hint to the action bar that the text title should appear. The action bar will show the title when possible, but might not if an icon is available and the action bar is constrained for space." - android developer
http://developer.android.com/guide/topics/ui/actionbar.html
it have two reason to not working always option:
there is no more space in actionbar because of too much icons.
if you are using custom theme then you have to use
yourapp:showAsAction="always"
rather than
android:showAsAction="always|withText"
Are you using the support library? If so, you are supposed to do it differently:
Android 4.3 menu item showAsAction="always" ignored

Custom Overflow Menu Outside of ActionBar

I need to implement a custom overflow menu with menu items and the overflow icon if the screen size cannot show all the icons. I cannot use a side scroll since I am already inside an expanded list view. I cannot use the Top or bottom action bar menu because the action will change based on what list item has been expanded.
So I would like to create my own overflow menu - similar to the gmail screenshots attached
Any ideas? Apparently ABS can be used for this but I can't figure it out, please help :)
ListPopupWindow is what you're looking for. It's an API 11+ class, however. ABS includes a backported version which is basically just a ListView inside a PopupWindow (both API 1 classes).

How to avoid duplicate menu buttons in devices with API>10

How can I remove or hide the soft menu button in the bottom bar but still keep the overflow menu button in the ActionBar.
I have set the target API to:
android:targetSdkVersion="11"
as suggested here.
My app does have menu items so I am overriding the onCreateOptionsMenu().
The menu button appears both in the right side of the ActionBar and in a bottom bar. I simple don't want the space in the bottom of screen to be wasted for a duplicate menu button. I have seen apps like YouTube or Google Play which only have menu button in the ActionBar so I assume there should be a way to do this.
Raising target API to 14 (android:targetSdkVersion="14") solved this problem.
with thanks to CommonsWare
`

Categories

Resources