android - 操作栏将菜单图标显示为溢出而不是单个图标

标签 android android-actionbar

发生了什么:

  1. 我在操作栏中有两个图标作为菜单
  2. 我的最小 sdk 是 8,最大是 21
  3. 这些图标显示在下拉列表中,而不是单独的图标
  4. 我使用的主题是Theme.AppCompat.Light.DarkActionBar
  5. 我的 Activity 正在扩展 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>

Styles.xml

<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>

最佳答案

您必须编辑 menu.xml 中的一行。只需编辑这两个菜单项的行即可

android:showAsAction="always"

通过使用这个,android将始终显示菜单项。如果菜单项不强制显示在操作栏上,我们通常使用 ifRoom。

关于android - 操作栏将菜单图标显示为溢出而不是单个图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27814196/

相关文章:

android - 使 ListView 中的项目可选择

android - Android 上的 RTSP 直播

android - 在水平 ScrollView 中单击时如何滚动到芯片?

android - 为什么 Android 应用程序在添加启动新 Activity 的按钮后会崩溃?

c# - 如何使用 Xamarin 更改 ActionBar 菜单项的 Action View

android - 是否可以在 ActionBar 上使用 TransitionDrawable?

java - 构建 apk(libgdx) 时 android studio 出错

android - 在android中绘制镜像位图

android - ActionBar 预 hive

java - 首选项屏幕以及半透明的导航和状态栏