1

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 2

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I will try that out. But it's still kind of dumb to solve the problem with a hack, when the documentation states that it should work when pressing the hardware menu button (when there is one). Thx
0

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

1 Comment

Thank u, but I've tried that. And it works for phones that do not have 'Menu' button, but on ones that do have, like Samsung Galaxy S2 or Samsung Galaxy S3, it does not appear at all (even if I click on the 'Menu' button, like it supposed to work)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.