bachr
bachr

Reputation: 6006

MenuItem showing up on a bottom bar

When I inflate the menu, some of the item are showing up in the bottom bar, while the others show up in the usual options menu of Android 2. I tried with android:uiOptions="none" in the manifest, but then the bottom bar disappear and the options menu remain.

What I want to do is to add a menu item to the action bar!

Here is the menu layout

<menu xmlns:android="http://schemas.android.com/apk/res/android" >  
<item
    android:id="@+id/menu_support"
    android:icon="@drawable/icon_close" 
    android:showAsAction="always"
    android:title="@string/menu_support"
    android:visible="true"/>    
<item
    android:id="@+id/menu_feedback"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/menu_feedback"/>    
<item
    android:id="@+id/menu_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/menu_settings"/>
</menu>

and here is the onCreateMenuOptions:

@Override
public boolean onCreateOptionsMenu(Menu menu) {             
    getSupportMenuInflater().inflate(R.menu.activity_main, menu); return true;
}

Upvotes: 1

Views: 2076

Answers (1)

Erik Nedwidek
Erik Nedwidek

Reputation: 6184

The options menu is always visible because the new design is for devices to not have a menu button.

I would guess that you have setDisplayShowHomeEnabled(false) and setDisplayShowTitleEnabled(false). Then when you set android:uiOptions to none, that would cause your Actionbar to go away, but keeps the options menu icon. You need to keep that as splitActionBarWhenNarrow if you're disabling the top Actionbar.

Finally to get to the crux of your question. You have one item that is set as android:showAsAction=always. That option will always show up as an icon on the action bar. The other two are set to never. They will always show up in the options menu.

never = show as an action icon on the action bar.

ifRoom = show as an action icon on the action bar if there is room on the action bar, but put in the options menu when there isn't room.

always = always shown in the option menu.

|withText = adds the hint to show the action's title if there is room on the action bar.

The rule of thumb is to only set two items as always shown as actions so that the Actionbar does not get crowded on small devices. On larger devices your ifRoom options will be displayed as Actionbar items rather than option menu items.

Upvotes: 2

Related Questions