Calvin Kung Calvin Kung - 5 months ago 23
Android Question

Overflow button on ActionBar not shown on Android Studio sample application

It seems similar question has been asked here before, but I can't the answer yet.

I am using the latest Android Studio, and create a new project, using the template "Navigation Drawer Activity".

The menu xml is like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="@+id/action_example" android:title="@string/action_example"
app:showAsAction="withText|ifRoom" />
<item android:id="@+id/action_settings" android:title="@string/action_settings"
app:showAsAction="never" />
<item android:id="@+id/action_test3" android:title="test3"
app:showAsAction="never" /></menu>


The Overflow button is not showing on the right upper corner. If I pressed android phone menu button, I can see the pop up on the lower part of the screen. How can I show the overflow button as seen on many other applications ?

The screen capture here:
https://drive.google.com/file/d/0B4khs9dLs4lIVlFCUnhNblR1ZU1wODU0MFdHalJsZkRLZlhv/view?usp=sharing

Answer

Try below code :

Put this inside your activity class if you want to Force to the Application to show the Action Overflow:

try {
    ViewConfiguration config = ViewConfiguration.get(this);
    Field menuKeyField = ViewConfiguration.class
            .getDeclaredField("sHasPermanentMenuKey");
    if (menuKeyField != null) {
        menuKeyField.setAccessible(true);
        menuKeyField.setBoolean(config, false);
    }
} catch (Exception ex) {
    // Ignore
}

For more information visit my another answer: Overflow menu not working