Reputation: 157
I have 5-6 items in my Action Bar. When I set ShowAsAction = "never"
, the items goes into the old styled menu which appears from bottom of the screen while I want the three dot styled icon to appear on Action Bar. Also when I click on it, the menu doesn't appear.
My menu file -
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/About"
android:title="About"
android:orderInCategory="1"
android:showAsAction="always"/>
<item
android:id="@+id/Settings"
android:title="settings"
android:orderInCategory="2"
android:showAsAction="always"/>
<item
android:id="@+id/item3"
android:title="Item3"
android:icon="@drawable/ic_launcher"
android:orderInCategory="3"
android:showAsAction="always"/>
<item
android:id="@+id/item4"
android:title="Item3"
android:icon="@drawable/ic_launcher"
android:orderInCategory="4"
android:showAsAction="always"/>
<item
android:id="@+id/item5"
android:title="Item3"
android:icon="@drawable/ic_launcher"
android:orderInCategory="5"
android:showAsAction="never"/>
<item
android:id="@+id/item6"
android:title="Item3"
android:icon="@drawable/ic_launcher"
android:orderInCategory="6"
android:showAsAction="never"/>
</menu>
Upvotes: 4
Views: 8803
Reputation: 101
Android disabled showing the overflow icon on devices which have physical menu button, for some of you who still want it,here is a solution:
add this function to your activity:
private void forceShowActionBarOverflowMenu() {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
and finally you add "forceShowActionBarOverflowMenu();" right after setContentView() in onCreate() in your activity.
Upvotes: 8
Reputation: 1014
nest the menu as the following way and you will get the overflow icon and also the icon of in drop down if you specified.
<item
android:id="@+id/empty"
android:icon="@drawable/ic_action_overflow"
android:orderInCategory="101"
android:showAsAction="always">
<menu>
<item
android:id="@+id/action_show_ir_list"
android:icon="@drawable/ic_menu_friendslist"
android:showAsAction="always|withText"
android:title="List"/>
</menu>
</item>
Upvotes: 5
Reputation: 44571
If you have a hard menu button on your device then the menu options that don't fit on the ActionBar
will be placed on your device's menu button. If you have a newer device without this button then they will be placed in the overflow menu (the 3 vertical dots)
I created a custom layout
for a custom ActionBar
so that I could have the same sort of look and functionality across all devices. You may consider doing the same thing if this is what you want.
Upvotes: 11