1

I am new to android and I am trying to create an overflow menu.

The 3 dots on the ActionBar are not showing (even after changing the app theme). After changing the app theme, it gets shown on the center of the screen "Android..CoordinatorLayout" how to get these 3 dots?

My menu_main.xml:

<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_settings" 
        android:title="@string/action_settings"
        android:orderInCategory="100"
        app:showAsAction="always" />

    <item android:id="@+id/rtfm" 
        android:title="@string/action_settings"
        android:orderInCategory="100"
        app:showAsAction="never" />
</menu>
Sufian
  • 6,405
  • 16
  • 66
  • 120
Abdul Rafay
  • 102
  • 2
  • 10
  • Please show us the code for your menu XML - you should use `android:showAsAction="never"` to get your overflow. – ishmaelMakitla May 30 '16 at 21:19
  • 1
    I think the answer to your question is here: [Android ActionBar items as three dots](http://stackoverflow.com/questions/27627659/android-actionbar-items-as-three-dots) – Nahue May 30 '16 at 21:19
  • i have added the code for menu XML – Abdul Rafay May 30 '16 at 21:42
  • 1
    @AbdulRafay Which device are you testing on? It will only show up on devices that don't have hardware `menu` button. Check [3 dot setting menu for android apps with custom title](http://stackoverflow.com/questions/18428396/3-dot-setting-menu-for-android-apps-with-custom-title/18428520#18428520) – Shobhit Puri May 30 '16 at 21:50

2 Answers2

3

You should need something like this.

A menu.xml layout for the items under the res/menu directory.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_settings"
        android:title="@string/action_settings"
        app:showAsAction="never" />
    ...
</menu>

Then in your Activity you must include this methods.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);

    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_settings:
            // Do something

            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Javier S.
  • 756
  • 8
  • 9
0

You can use this trick at Activity's onCreate:

if (savedInstanceState == null) {
    //Show dots:
    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
    }

} else {
    //isResumed = true; ............. do something.....
}
Anh Pham
  • 2,108
  • 9
  • 18
  • 29
РСИТ _
  • 325
  • 1
  • 14