Android toolbar not showing overflow menu

孤街醉人 提交于 2019-12-01 05:56:42

I Guess you missed this

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

if your phone has a physical menu button you can't see three dots

if you want to force to show three dots do as follow:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/menu"
    app:showAsAction="always"
    android:icon="@drawable/ic_action_overflow"
    android:visible="true" >
 <menu>
    <item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:title="@string/action_settings"
    app:showAsAction="never"
    android:visible="true" />
 </menu>
</item>

Solution: i've tried the following method and i've found the issue.

I think this is refering that theme to Theme.AppCompat.Light that's why this theme has a toolbar.

i just did this and it's working:

<resources>
    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
    </style>

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

Results:

it's working. but,

With your codes and getSupportActionBar();:

Note that our Toolbar has a gray color like this:

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/darker_gray"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

P.s: Also i want to make sure you'll do that perfectly, as doc said, we have to add this to Manifest:

<application
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    />

and seems like it's not working or we've lost something.BTW, i didn't do that on my manifest and that fixed without above code on manifest.

I had the same problem. I tried everything here and here, and nothing helped. Everything was just like it should be. After whole day of investigating, I found this statement in my onCreate method:

toolbar.setVisibility(View.INVISIBLE);

When I removed it, geuss what happend: 3 dots menu appears now, just like it should.

After following all the answer's suggestions, the overflow button was still not showing. This is how I solved it:

  • Make sure to override both methods "onPrepareOptionsMenu" and "onCreateOptionsMenu" in your activity
  • Return always true.

Check return comments for this methods on Activity.java :

@return You must return true for the menu to be displayed, if you return false it will not be shown.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!