I want to display a menu item only as an item of the overflow menu. Can I do this? For example, I have three fragments from which I want to be able to go to settings by clicking the menu item in the action bar. The first fragment has (all together with the settings) three menu items, the second two, and the last only one. I want 'settings' to be showed in all three of them in the overflow menu, no matter there is room or not.
2 Answers
My solution was a bit of a hack but it seemed to work for my g3 users. I created a menu item called overflow that has the overflow drawable as the icon.
Then, inside that item i nested a submenu that has the item i wanted to always display as overflow. I've only tested it on a handful of devices but it seemed to work for nexus 1 and Samsung g3 which were the 2 problem children i had to address.
<item
android:id="@+id/rest_overflow_menu"
android:icon="@drawable/abs__ic_menu_moreoverflow_normal_holo_dark"
android:showAsAction="ifRoom"
android:title="@string/clear"
android:visible="true">
<menu>
<item
android:id="@+id/rest_filter_clear"
android:showAsAction="always"
android:title="@string/clear"
android:visible="true"/>
</menu>
</item>
Hope this helps
1 Comment
Ok for each of these fragments you're going to want to set up a context menu for your 3-2-1 menu item listing.
http://developer.android.com/guide/topics/ui/menus.html#context-menu
now then for your 'settings' menu item, you need to set when to show as action when it is added to the actionbar/menu
MenuItem item= menu.add(R.string.item_id);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
http://developer.android.com/reference/android/view/MenuItem.html