Action-bar - a submenu item with text and image does not work properly

I am developing a small Android application in which I use the action bar with some menu items. One menu item contains submenus. Now I want to display a menu item with text and an icon always.

I define the menu items as follows.

<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, my action bar displays my items correctly; The only thing is that when the window is in portrait mode, it displays only the image, and when the window is in landscape mode, it displays the image and text. But I want image and text in both modes.

How to do it? Is there any way to solve this?

+6
android android-actionbar menu submenu
Feb 18 '13 at 8:34
source share
2 answers

If you use the ActionBar from the Android Sopport Library ( android.support.v7.app.ActionBar ), you may need to change the declaration of your menu and item 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"/> 

to

 <!-- 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"/> 

I had a similar problem while ensuring compatibility with older versions of Android.

+1
Sep 18 '13 at 18:23
source share

it's better to use android:showAsAction="ifRoom|withText" than always .
In this case, the size of your text and the width of the screen depend.

0
Apr 21 '13 at 7:53 on
source share



All Articles