Android Action Bar add all icon to overflow - android

I am updating my apps to have action bars, as Google seems to want developers to do now, and I am trying to get all the options of one app to all be in the overflow menu. I have searched far and wide but I can't seem to find anything that would make them do that. I'm pretty sure it would be something in the xml that defines the menu items. Do any of you guys know how to make all the menu options be in the overflow menu?

As CommonsWare said, showAsAction is the key.
Set android:showAsAction="never" on the if you are inflating an xml or use item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); if you are creating the items with code.
You should consider using android:showAsAction="ifRoom" or item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); since the actionbar will contain a lot of empty space, if you don't fill it with something else that is.

They will all be in the overflow menu by default. You have to specifically do things to your menu resource XML files to change that, notably have android:showAsAction attributes on the <item> elements.

Related

Divider lines in overflow menu

Is it possible to put divider lines between groups of menu items in an overflow menu in Android?
Dividers are a standard feature of menus, and have been for at least 30 years. So it seems a bit weird if this isn't possible in a non-trivial way.
For example, the Chrome menu on OSx looks like this:
I'm talking about the lines between some of the menu items. Is there a way to get something similar in the overflow and/or context menus in Android without resorting to custom views and whatnots?

Why have android:actionLayout and android:icon at the same time?

I am reading about action bars in BusyCoder's Android guide. There is an example:
<item
android:id="#+id/add"
android:actionLayout="#layout/add"
android:icon="#android:drawable/ic_menu_add"
android:showAsAction="ifRoom"
android:title="#string/add"/>
What is the point to have both android:actionLayout and android:icon defined? What are the conditions when the icon would show up?
Thanks for helping out Android noob
What are the conditions when the icon would show up?
I can't rule out the possibility that the action bar will decide that there is not enough room for the actionLayout, but there is enough room for an action item, which would therefore show the icon. Also, with ActionBarSherlock, the icon is shown even in the overflow on Android 2.x devices, and so again if the actionLayout would be too large, the icon might get used. Also, if I used ifRoom|collapseActionView instead of just ifRoom, the icon would be used.
That being said:
My sample does not actually watch for this theoretical action item, should it appear, to do anything if the user clicks on it
I am guessing at possible action bar behavior, as I have not tried any experiments to force the action bar to decide whether there is enough room for all actionLayout-configured items
here android:icon is defined to supply an icon for your menu item. This is always optional but it is recommended to have an icon for the menu item.
android:actionLayout is defined to supply a custom view for the menu item again this is optional but if u need some Image Views, Text Views, Edit Text Views etc. in your menu item, this is the way to go.
If you need more help see these guides. These I think will be more helpful to you.
Action Bar Android Developer Guide
Menu Resource Android Developer Guide
Also take a look at this example. This may give you a much better idea about android Action bars.
vimaltuts.com/android-tutorial-for-beginners/android-action-bar-tab-menu-example
Thank You!

Overflow icon is not coming the Actionbar of ActionBarSherlock

I am new to Android. I am trying to use Actionbarsherlock in my application. I tried the following code in the onCreateOptionsMenu :
menu.add("Save").setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add("Edit").setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add("Clear").setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add("Refresh").setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add("Save all").setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
But i am not getting the overflow icon in the actionbar. I understood its a silly mistake. But i couldn't find where it is. Please help me to fix it!
Since you are asking for MenuItem.SHOW_AS_ACTION_ALWAYS I think none of the Menu Items go in to OverFlow.
Also, If the device has a hardware menu button, then the extra icons will not go in to overflow, instead you can access them using the menu button.

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 explicitelly add items to the overflow menu in the actionbar

I was wondering if it is possible to put items directly in the overflow menu on the actionbar. I am using ActionbarSherlock for my app (if this is relevant). I have several menu items, for instance: Add, Delete, Sort, About app, etc. These are all items for my actionbar menu. I would like to leave only "Add" outside, and put the rest in the overflow menu. Is there any way to do that?
I was wondering if it is possible to put items directly in the overflow menu on the actionbar.
Yes, set the attribute showAsAction to "never":
<item android:id="#+id/item"
android:title="#string/item"
android:showAsAction="never"/>

Categories

Resources