我正在开发中,我使用操作栏的一些菜单项小的Android应用程序。一个菜单项包含子菜单。现在,我想要做的是与文本和图标总是显示菜单项。
I am developing small Android application in which I am using action bar with some menu items. One menu item contains sub menu. Now what I want to do is to display menu item with text and icon always.
我在下面的方式定义菜单项。
I define menu items in following manner.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/card_menu"
android:icon="@drawable/abc"
android:showAsAction="withText|always"
android:title="cards">
<menu>
<item
android:id="@+id/C1"
android:title="C1"/>
<item
android:id="@+id/C2"
android:title="c2"/>
<item
android:id="@+id/C3"
android:title="C3"/>
</menu>
</item>
<item
android:id="@+id/notification"
android:actionLayout="@layout/notification_icon"
android:icon="@drawable/notification"
android:showAsAction="always"
android:title="Notifications"/>
<item
android:id="@+id/filter"
android:icon="@drawable/filter"
android:showAsAction="always"
android:title="Filter"/>
</menu>
现在发生的事情是我的行动吧正确地显示我的项目;唯一的一点是,当窗口处于纵向模式只显示图像,而当窗口是在横向模式下它显示的图像和文字两种。但我想在这两个模式下的图像和文字。
Now what happens is my action-bar displays my items properly; only thing is that when window is in portrait mode it shows only image, and when window is in landscape mode it shows image and text both. But I want image and text in both mode.
如何做到这一点?请问有什么办法可以解决这个问题?
How to do that? Is there any way to solve this?
如果您使用的是动作条从Android前缀相同库(的 android.support.v7.app.ActionBar ),你可能需要改变你的菜单项声明:
If you are using the ActionBar from the Android Sopport Library (android.support.v7.app.ActionBar), you might need to change your menu and item declaration from:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/notification"
android:actionLayout="@layout/notification_icon"
android:icon="@drawable/notification"
android:showAsAction="always"
android:title="Notifications"/>
到
<!-- Your menu -->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourappname="http://schemas.android.com/apk/res-auto" >
<!-- Your item to be shown as action-->
<item
android:id="@+id/notification"
android:actionLayout="@layout/notification_icon"
android:icon="@drawable/notification"
android:showAsAction="always"
yourappname:showAsAction="always"
android:title="Notifications"/>
在提供兼容旧的Android版本时,我也有类似的问题。
I had a similar problem when providing the compatibility to older android versions.
上一篇:ActionBar的溢出菜单打开/关闭监听器监听器、菜单、ActionBar
下一篇:HTML:为什么Android浏览器显示&QUOT; GO&QUOT;而不是&QUOT;接下来&QUOT;在键盘上?而不是、接下来、键盘、浏览器