Overflow not showing in action bar

I have 5-6 items in the action bar . When I set ShowAsAction = "never" , the items enter the old styled menu that appears at the bottom of the screen, while I want the three-dot icon to appear in the action bar . Also, when I click on it, the menu does not appear.

My menu file is

  <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> 
+4
source share
3 answers

If you have a hard menu button on your device, then menu options that are not suitable for ActionBar will be placed on the menu button of your device. If you have a new device without this button, they will be placed in the overflow menu (3 vertical dots)

See Creating a Settings Menu.

I created a custom layout for a custom ActionBar so that I can have the same look and functionality on all devices. You can do the same if that is what you want.

+10
source

Android is disabled, showing an overflow icon on devices that have a physical menu button, for some of you that still want this, here is the 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.

+8
source

insert this menu as follows and you will get an overflow icon as well as an icon in the drop-down list 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> 

+5
source

Source: https://habr.com/ru/post/1488749/


All Articles