Android Actionbar将菜单图标显示为溢出,而不是单个图标

Android Actionbar将菜单图标显示为溢出,而不是单个图标,android,android-actionbar,Android,Android Actionbar,发生了什么: 我在actionbar中有两个图标作为菜单 我的最小sdk为8,最大sdk为21 这些图标显示在下拉列表中,而不是单个图标 我使用的主题是Theme.AppCompat.Light.darkaActionBar 我的活动正在扩展ActionBarActiviy 我想要什么: 我想显示为单个图标 Menu.xml <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.an

发生了什么:

  • 我在actionbar中有两个图标作为菜单
  • 我的最小sdk为8,最大sdk为21
  • 这些图标显示在下拉列表中,而不是单个图标
  • 我使用的主题是
    Theme.AppCompat.Light.darkaActionBar
  • 我的活动正在扩展
    ActionBarActiviy
  • 我想要什么:

    我想显示为单个图标

    Menu.xml

    <?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/icnMenuWalletId"
            android:icon="@drawable/wallet"
            android:showAsAction="ifRoom"
            android:title="WALLET">
        </item>
        <item
            android:id="@+id/icnMenuTwoId"
            android:icon="@drawable/notification"
            android:showAsAction="ifRoom"
            android:title="NOTIFICATIONS">
        </item>
    
    </menu>
    
    <resources>
    
        <!--
            Base application theme for API 11+. This theme completely replaces
            AppBaseTheme from res/values/styles.xml on API 11+ devices.
        -->
        <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- API 11 theme customizations 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>
    
         <!-- Application theme. -->
        <style name="AppThemeSplash" parent="AppBaseTheme">
            <!-- All customizations that are NOT specific to a particular API-level can go here. -->
             <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    
        </style>
    
    
    </resources>
    
    
    
    Styles.xml

    <?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/icnMenuWalletId"
            android:icon="@drawable/wallet"
            android:showAsAction="ifRoom"
            android:title="WALLET">
        </item>
        <item
            android:id="@+id/icnMenuTwoId"
            android:icon="@drawable/notification"
            android:showAsAction="ifRoom"
            android:title="NOTIFICATIONS">
        </item>
    
    </menu>
    
    <resources>
    
        <!--
            Base application theme for API 11+. This theme completely replaces
            AppBaseTheme from res/values/styles.xml on API 11+ devices.
        -->
        <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- API 11 theme customizations 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>
    
         <!-- Application theme. -->
        <style name="AppThemeSplash" parent="AppBaseTheme">
            <!-- All customizations that are NOT specific to a particular API-level can go here. -->
             <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    
        </style>
    
    
    </resources>
    
    
    真的
    假的
    真的
    @空的
    
    尝试此操作,并确保已将包名
    工具:context=“com.abc.android.HomeActivityNew”
    更改为包名,希望对您有所帮助

    <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.abc.android.HomeActivityNew" >
    
            <item
                android:id="@+id/icnMenuWalletId"
                android:icon="@drawable/wallet"
                android:showAsAction="always"
                android:title="WALLET">
            </item>
            <item
                android:id="@+id/icnMenuTwoId"
                android:icon="@drawable/notification"
                android:showAsAction="always"
                android:title="NOTIFICATIONS">
            </item>
    
        </menu>
    
    
    
    更改

    android:showAsAction="ifRoom" 
    


    ifRooom用于将项目移动到溢出菜单,如果没有空间容纳它

    则必须编辑menu.xml中的一行。只需编辑两个菜单项的行

    android:showAsAction="always"
    
    通过使用此选项,android将始终显示菜单项。如果菜单项不是必须显示在actionbar上,我们通常使用ifRoom