2

In my android application, I have an item in the menu, and I want the item display all the time with the icon and the text, this is the setting:

<item
        android:id="@+id/menu_submit_back_tomap"
        android:title="@string/menu_back_tomap"
        android:icon="@drawable/ic_action_back"
        android:showAsAction="always|withText"/>

However I can only see the icon, the text is not displayed, what's the problem?

BTW, this is the only item in the menu.

hguser
  • 35,079
  • 54
  • 159
  • 293
  • possible duplicate of [How to display both icon and title of action inside ActionBar?](http://stackoverflow.com/questions/12000562/how-to-display-both-icon-and-title-of-action-inside-actionbar) – Blo Apr 09 '14 at 04:30
  • If there is only one icon and text is short maybe *ifRoom|withText* might work to diplay both. – Blo Apr 09 '14 at 04:43
  • Both `ifRoom|withText` and `always|withText` do not work. – hguser Apr 09 '14 at 08:34

3 Answers3

3

It depend on available space if there will be space to display text it will be displayed if not then only icon will be displayed.

" The "withText" value is a hint to the action bar that the text title should appear. The action bar will show the title when possible, but might not if an icon is available and the action bar is constrained for space." - android developer

http://developer.android.com/guide/topics/ui/actionbar.html

DjP
  • 4,537
  • 2
  • 25
  • 34
2

it have two reason to not working always option:

  1. there is no more space in actionbar because of too much icons.
  2. if you are using custom theme then you have to use

    yourapp:showAsAction="always"
    

    rather than

     android:showAsAction="always|withText"
    
Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
0

Are you using the support library? If so, you are supposed to do it differently:

Android 4.3 menu item showAsAction="always" ignored

Community
  • 1
  • 1
korbonix
  • 126
  • 1
  • 3