Android - keep options menu open

I have a Options menu in my Android application, and I have overridden the onCreateOptionsMenu, onOptionsItemSelected, and onPrepareOptionsMenu methods to customize the menu a bit.

My question is related to saving the "Options" menu after the user clicks on the menu item. Basically, I would like to hide the menu until the user clicks on the device’s menu button. As soon as the user clicks on this key, I would like to be able to keep the menu in place, no matter how many times the user clicks on the menu items. If the user wants to hide the Options menu, they just need to press the device’s menu button again.

Whether this type of interaction is supported (or even appropriate). If this interaction is not supported, any alternative suggestions are more than welcome.

Hooray!

Sean

+7
android menu
source share
3 answers

This is not possible with onCreateOptionsMenu and other methods. They always do that.

But you can do it differently. But there you need to program all the menus yourself. Basically add a menu to your layout.xml and let it hide (visibility = no). Then you overwrite the onKeyDown methods. There you check to see if it is a Menu key. if the menu is not already open yes, then you show the menu. If it is already open, you hide it.

should not be too complicated. The good thing also is that you can customize the menu the way you want, and also let it react the way you want.

+5
source share

For anyone who finds this question on Google, there is a way to solve it here: How to hold the overflow menu after I click on it?

0
source share

For anyone like me who has found this question on Google:

To keep the menu open after selecting an item, you need this code:

@Override public boolean onOptionsItemSelected(MenuItem item) { item.setChecked(!item.isChecked()); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); item.setActionView(new View(this)); item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { return false; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { return false; } }); return false; } 

It is important to return false in onOptionsItemSelected and OnActionExpandListener methods

This is a solution from @MayurGajra. Read more here: How to hold the overflow menu after I click it?

0
source share

All Articles