Mehmet Emin Acar Mehmet Emin Acar - 1 year ago 86
Android Question

Display menu item in both action bar and menu key

I have a menu item in res/menu/mymenu.xml:

<menu xmlns:android="" >

android:showAsAction="ifRoom" />


But when I press menu key the menu doesn't appear. It only shows in action bar. Also I tried
but that time the item only shows in the menu key screen. I want to display the item both in action bar, and in the screen that shows when I press menu key.
Thanks in advance.

Answer Source

Bear in mind that all menu items are displayed only once. You cannot instruct the menu to display a single menu item twice, whether that's once in the overflow, and once in the action bar.

With android:showAsAction="never", you're instructing Android to tuck the menu item away into the overflow menu. (On devices without a hardware menu button, the menu item will display in the action bar overflow. On devices with a hardware menu button, the menu item will display in a pop-up menu from the bottom of the screen, which is also known as the action bar overflow.)

With android:showAsAction="always", you do the opposite; it will always appear in the action bar, whether or not there's enough room.

Although I thoroughly discourage your from taking this approach, strictly answering your question is to provide two menu items: one with mode never, the other with mode always.

I would instead suggest you reconsider whether you want the item in the overflow menu or not. Consider carefully Google's recommendations on the action bar, and either display it or place it in the overflow--not both. Also bear in mind that different device configurations may allow for more items displayed if there is enough room when using ifRoom.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download