发生了什么:
- 我在操作栏中有两个图标作为菜单
- 我的最小 sdk 是 8,最大是 21
- 这些图标显示在下拉列表中,而不是单独的图标
- 我使用的主题是
Theme.AppCompat.Light.DarkActionBar
- 我的 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/