How to force action bar overflow icon to show

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.

  • Iterate through rows from Sqlite-query
  • Custom view in xml layout
  • causing a java.IllegalStateException error, No Activity, only when navigating to Fragment for the SECOND time
  • Waiting for a Runnable to complete before running another Runnable
  • Galaxy Nexus Ignores viewport meta tag
  • How do I lock screen orientation for phone, but not for tablet? (Android)
  • 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.

  • Simulate Mock Location on Android Device via DDMS
  • Android multidex not supporting with proguard
  • Programmatically create TextView with ellipsis
  • Eclipse Android - Logcat Clearing too Fast
  • How to create a helpful tooltip in Android
  • How can I tell ProGuard to keep my function that is used for onClick?
  • 2 Solutions collect form web for “How to force action bar overflow icon to show”

    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.

    This could be another work around, which really helped me. Keep one drawable with three dots and give it as a menu item.

    <?xml version="1.0" encoding="utf-8"?>
     <menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
    
    <item
        android:id="@+id/saveDetails"
        android:showAsAction="always"
        android:title="@string/save"/>
    
    <item
        android:id="@+id/menu_overflow"
        android:icon="@drawable/dts"
        android:orderInCategory="11111"
        android:showAsAction="always">
        <menu>
            <item
                android:id="@+id/contacts"
                android:showAsAction="never"
                android:title="Contacts"/>
    
    
            <item
                android:id="@+id/service_Tasks"
                android:showAsAction="never"
                android:title="Service Tasks"/>
    
    
            <item
                android:id="@+id/charge_summary"
                android:showAsAction="never"
                android:title="Charge Summary"/>
    
    
            <item
                android:id="@+id/capture_signature"
                android:showAsAction="never"
                android:title="Capture Signature"/>
        </menu>
    </item>
    
    </menu>
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.