Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force action bar overflow icon to show

Tags:

I would like to force the overflow icon to always show in the action bar (assuming there are overflow items). On models with a menu button, sometimes the overflow icon doesn't appear and users must tap the devices menu button to get the rest of the action menu items. Users keep complaining about this.

Note that for the context menu, the overflow icon always shows, regardless of whether the device has a built in menu button or not.

I realize that forcing the overflow icon to appear in the action bar would duplicate the functionality of the "physical" one. You might consider that violating Androids design guidelines. In my opinion, though, the users win. They say it's confusing and I believe they're right.

like image 421
Peri Hartman Avatar asked Dec 07 '13 17:12

Peri Hartman


People also ask

Where is the action overflow menu icon?

The right-hand side of the action bar shows the actions. The action buttons (3) show the most important actions of your app. Actions that do not fit in the action bar are moved to the action overflow, and an overflow icon appears on the right.

How do I show the menu icon on Android?

Click res → New → Vector Asset . Choose the icon that you want by clicking on the android icon, click “Next” button and then click “Finish”. 6- Now we can add android menu items with icons, we will have 4 menu items. 1 menu item will be the root while the other 3 menu items will be grouped under a single Menu .

What is overflow menu icon?

The overflow icon is a common UI convention that's leveraged throughout Android to hide settings and other unimportant options. Google is now replacing it in the Play Store with a “tap & hold” gesture and bottom sheet menu.


1 Answers

Congratulations! You won!

As of Android 4.4, the ... affordance in the action bar will be there, regardless of whether the device has a physical MENU button or not. Google's current Compatibility Definition Document now comes out a bit more forcefully against having a dedicated MENU button.

The hack that developers have used in the past, to get this behavior, is:

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) {   // presumably, not relevant } 

That should not be needed on Android 4.4+, though with the exception handler in place, I would not expect any particular problem if you run it and, someday, they get rid of sHasPermanentMenuKey outright.

Personally, I still wouldn't change things on Android 4.3 and below, as I suspect it's a whack-a-mole situation, where you will replace complaints about having no menu with complaints about having duplicate versions of the same menu. That being said, since this is now the officially endorsed behavior going forward, I have no problems with developers aiming for consistency on older devices.

A hat tip to the commenter on the issue I filed regarding this, pointing out the change.

like image 109
CommonsWare Avatar answered Oct 25 '22 15:10

CommonsWare