1

I have an icon that I want to display with some text in my action bar. However, no matter what I do (change text to display always, have the text be a single letter so there's definitely room, etc) I can't get both to display (the icon always displays fine), but only on xhdpi screens. If I run it on 240dpi or lower it displays both. I've read in googling that text not being displayed with the icon was a bug in ICS, but I'm testing on API 19. Is there a solution to this? thanks

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item 
    android:id="@+id/action_dafuq"
    android:icon="@drawable/dafuq"
    android:title="@string/dafuq"
    android:showAsAction="ifRoom|withText" />

</menu>
Daniel H
  • 389
  • 4
  • 19

2 Answers2

0

You can use SpannableString and inject your icon before text ! Something like this:

final MenuItem action_dafuq = menu.findItem(R.id.action_dafuq);;
final ImageSpan icon = new ImageSpan(getContext(), R.drawable.icon);
final SpannableString title = new SpannableString("  " + "dafuq");
title.setSpan(icon, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
action_dafuq.setTitle(title);

I hope this works.

Ali Mehrpour
  • 603
  • 8
  • 16
0

Strange that a higher resolution screen doesn't show both comparing with lower ones. Anyway, I would suggest you to check how it works on landscape orientation.

If you don't have so much icons to be display you could try force always show icon+text combining always and withText tags

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item 
    android:id="@+id/action_dafuq"
    android:icon="@drawable/dafuq"
    android:title="@string/dafuq"
    android:showAsAction="always|withText" />

</menu>

Another option, you can inflate the actionbar item layout and customize then using an adapter: Actionbar styled overflow menu items

Community
  • 1
  • 1
Fabio Farath
  • 489
  • 6
  • 12