Android actionbar always showing overflow menu for menu items in actionbar

◇◆丶佛笑我妖孽 提交于 2019-12-25 16:43:55

问题


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>


来源:https://stackoverflow.com/questions/26155963/android-actionbar-always-showing-overflow-menu-for-menu-items-in-actionbar

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