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>
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)
See Creating an Options Menu
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With