简体   繁体   中英

Overflow Menu doesn't show

I have a problem with my app...the overflow menu is invisible! I can physically tap on the top-right part of my phone and the menu items show, but the three dots do not show.

Here is my 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="com.android.example.MainActivity">

    <item
        android:orderInCategory="1"
        android:id="@+id/ic_home"
        android:title="Home"
        android:icon="@drawable/ic_home"
        app:showAsAction="withText"
        />

    <item
        android:orderInCategory="2"
        android:id="@+id/ic_chat"
        android:title="Forum"
        android:icon="@drawable/ic_chat"
        app:showAsAction="withText"
        />

    <item
        android:orderInCategory="3"
        android:id="@+id/ic_videos"
        android:icon="@drawable/ic_videos"
        android:title="Videos"
        app:showAsAction="withText"
        />

    <item
        android:orderInCategory="4"
        android:icon="@drawable/ic_timeline"
        android:id="@+id/ic_timeline"
        android:title="Timeline"
        app:showAsAction="withText"
        />

    <item
        android:icon="@drawable/ic_phone"
        android:id="@+id/ic_call"
        android:orderInCategory="5"
        android:title="Call"
        app:showAsAction="withText"
        />   

</menu>

Java code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    return super.onOptionsItemSelected(item);
}

I have tried other solutions on StackOverflow, but none of them seem to work. I have tried running the app on 2 phones, both with Android version > 4.4.

Update: I tried adding a navigation drawer to the app. Again, when I tap on the side where the drawer button is supposed to be, the menu shows up, but the button is not visible...

Update 2: I tried changing my theme settings in style.xml. When I made the windowActionBar to true instead of false and the windowNoTitle to false instead of true, both the drawer and the overflow menu show up. However, my toolbar shows up below the action bar like this .

How do add the menu buttons to the actual (white) toolbar?

Thanks in advance.

Have you setup toolbar :

Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

Check out this answer for full explanation.

Remove onCreateOptionsMenu and onOptionsItemSelected and use it like this

 Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar);
    toolbar.inflateMenu(R.menu.main_menu);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override 
        public boolean onMenuItemClick(MenuItem item) {
            return false;
        }
    });

or if you are in frgment not in acivity then you have to add this line of code in onCreateView

         setHasOptionsMenu(true);

OK I found the answer:

I got the default action bar back again and then created a layout resource file for a custom action bar.

I added the design/specs of the desired bar in the custom action bar file and then set the action bar to the custom action bar file.

It all worked out!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM