Android: Overflow icon event listener - android

Does anyone know how to add a listener to the action overflow menu button ( the three dots on the action bar )?
I would like to add elements dynamically to the overflow menu, and I can't figure out how to do it.
Help please :)

Does anyone know how to add a listener to the action overflow menu button
You don't.
I would like to add elements dynamically to the overflow menu
You can try invalidateOptionsMenu() at the point when you know that you want different menu choices than what you had set up previously. However, I have heard reports that this may not affect the action bar.
If the "dynamic" aspect is based on fragments coming and going, have your fragments implement the option menu items (via overriding onCreateOptionsMenu() and calling setHasOptionsMenu(true)). Android will add and remove items based on the changing mix of fragments on the screen.

Related

open action bar overflow menu programatically in Android app

I need to open android support library action bar overflow menu (the one shown with three vertical dots) programatically. I know its a silly requirement but one of my client is insisting that they want the menu option to be opened and visible when user tap on a button in an activity.
Any pointer on how to do this will be highly appreciated.
Try using openOptionsMenu in your Activity.
You can do something similar to this implementing your own custom ActionProvider Check this out, in the "Creating a custom action provider" section.
Hope it helps

How to get notified when when action items get into the overflow menu?

When you put a lot of action items on the action bar, some of them get to be inserted into the overflow menu, or become available by clicking on the menu button (if present).
Is there a way to be notified when this occurs? Maybe even know which items got to be into the overflow menu (or available via the menu button) ?
Again, I don't ask how to put items there and I don't need to get explanation about how to define action items. I ask how to know when and which items get to be there.
You cannot decide which item to be into Action overflow menu but you can decide which to be shown always on Action bar.
You can also use "always" to declare that an item always appear as
an action button. However, you should not force an item to appear in
the action bar this way. Doing so can create layout problems on
devices with a narrow screen. It's best to instead use "ifRoom" to
request that an item appear in the action bar, but allow the system to
move it into the overflow when there's not enough room. However, it
might be necessary to use this value if the item includes an action
view that cannot be collapsed and must always be visible to provide
access to a critical feature.
http://developer.android.com/guide/topics/ui/actionbar.html

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).

Dropd down tabs or drop down menus beneath ActionBar in Android

My need is to add a drop down menu like the one shown in attached image link.
http://i.imgur.com/cWtykfN.jpg
I don't know what to be used, whether it is tabs or menus. My need is when I press the last tab/menu, the sub menu should be shown and I could be able to handle the corresponding actions. Even when I handle those menus, I should be able to show the top tab/ menu without interruption.
It's called as overflow menus. Look this example, you will get an idea.
http://wptrafficanalyzer.in/blog/adding-action-items-and-overflow-menu-items-to-action-bar-in-android/
And nice explanation been given here. http://blog.stylingandroid.com/archives/1249 and for source code.ref here: https://github.com/StylingAndroid/StylingActionBar/Tree/StylingPart2
Use the ActionBar with tab-navigation-mode and if the last tab is clicked you could simply trigger a PopupMenu (even though this seems a little weird and is not what I expect to happen when I click tab).

How to arrange menu items in action bar to my liking ?

i was wondering if anyone could tell me how to choose which menu items go in to the actiobar and which ones go into the overflow menu, i have five menu items and the ones i want in the actionbar go in the overflow and the one i want in the overflow are in the actiobar.
How can i rearrange the actionbars?
Any help will be appreciated
There are two things you can do.
First you can set the flag
android:showAsAction="ifRoom"
This will show items if there is room, if not they will be placed in the overflow menu.
Second, the XML file is scanned linearly. So just put your actions that you in the overflow menu to the bottom.
The documentation states
Menu items that are not promoted to an action item are available in the overflow menu, revealed by
either the device Menu button (when available) or by an "overflow menu" button in the action bar
(when the device does not include a Menu button).
Here is also an good post with more information.
How to force overflow menu on android actionbar compat?

Categories

Resources