Android actionbar always showing overflow menu for

2019-09-15 17:47发布

问题:

Hi I am developing sample Android application in which I am trying to display menu items in actionbar. But my actionbar always showing overflow menu even if there is only single menu item. It is not showing my menu items image in action bar. I have implemented this in following manner

    <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:compat="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.samplechromiapp.MainActivity" >

    <item
        android:id="@+id/categories"
        android:icon="@drawable/navigation_collapse"
        android:showAsAction="ifRoom|withText"  
        android:title="Categories"
        android:visible="true"
        />
</menu>

Am I doing anything wrong? Need some help. Thank you.

回答1:

Try this code and add extra xmlns attribute for your menu and try app:showAsAction instead of android:showAsAction

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

        <item
            android:id="@+id/categories"
            android:icon="@drawable/navigation_collapse"
            android:title="Categories"
            app:showAsAction="always"/>

 </menu>