3

I have an ActionBar that should display the action buttons in a custom way. For this I created a custom view and attached it to the ActionBar.

One thing to mention is that I am using a menu.xml resoure file to load the options menu and display them on a smartphone, but do not display them on tablet, instead use a custom view. For this I market every menu item in the xml as: android:showAsAction="never"

Everything looks fine, except one little thing that still remains on the right of the ActionBar - the "More" button.

How can I remove it?

enter image description here

I tried this:

ActionBar bar = activity.getActionBar();
bar.removeAllTabs();

but the "more" button still remains there.

EDIT:
This is my menu.xml file:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/menu_username"
        android:icon="@drawable/menu_username"
        android:orderInCategory="0"
        android:showAsAction="never"
        android:title="@string/menu_username">
        <menu>
            <item
                android:id="@+id/menu_logout"
                android:title="@string/menu_logout"/>
        </menu>
    </item>

    <item
        android:id="@+id/menu_settings"
        android:icon="@drawable/menu_settings"
        android:orderInCategory="1"
        android:showAsAction="never"
        android:title="@string/menu_settings"/>

    <item
        android:id="@+id/menu_search"
        android:icon="@drawable/menu_search"
        android:orderInCategory="1"
        android:showAsAction="never"
        android:title="@string/menu_search"/>

</menu>

Please note I still want to inflate this menu on a smartphone, but don't want to use it on a tablet.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
  • That should only appear in your action bar if you have items in it. Please post your `menu.xml` resource and where/how you are using it. Also, this has nothing to do with tabs in the action bar, which is why your `removeAllTabs()` call had no effect -- this is not a tab, but the overflow affordance. – CommonsWare Jun 09 '12 at 12:49
  • What that says is "I want all three items to be in the overflow". This is why I asked you to show where/how you are using that resource. – CommonsWare Jun 09 '12 at 13:48

1 Answers1

2

Setting showAsAction="never" will force an menu item into the overflow. Why not check in onCreateOptionsMenu(...) that the device is a tablet, and if it is just not inflate the menu? Something like this:

public boolean onCreateOptionsMenu(Menu menu) {
    if (getResources().getConfiguration().smallestScreenWidthDp >= 600) {
        //It's a tablet, don't inflate, only create the manual view
        manualMenuCreation();
    } else {
        getMenuInflater().inflate(R.menu.menu, menu);
    }
    return true;
}

Don't forget smallestScreenWidthDp is only available in 3.2 or above, so you'll have to take that into consideration.

Alex Curran
  • 8,818
  • 6
  • 49
  • 55
  • I know its an old answer but please tell me what is this method manualMenuCreation()? – vjs3 Dec 29 '15 at 11:55