0

I'd like to have one of the MenuItems in my app's action bar change colour based on its value. There are other items which should retain the default style so I can't apply styles to the whole action bar, it's got to just be to this one item. I've tried using a SpannableString like so:

MenuItem item = getActionBar().findItem(R.id.item_id);
SpannableString colouredString = new SpannableString("Item");

colouredString.setSpan(new ForegroundColorSpan(
    booleanStatement ? Color.RED : Color.GREEN
), 0, colouredString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

item.setTitle(colouredString);

This sets the value correctly, but the item's text colour is unaffected. If I add in

getActionBar().setTitle(colouredString);

then the title is set as expected, with the text colour applied. Is there a way of making SpannableString work on MenuItems as well as the overall action bar title? Or an alternative way of setting the text colour of an action bar menu item?

Isaac
  • 73
  • 2
  • 8
  • 1
    Have You tried this one http://stackoverflow.com/questions/8598015/different-look-style-for-specific-menu-item-on-actionbar ? – sandrstar Oct 26 '13 at 07:15
  • That's exactly what I wanted...somehow didn't come up in my searches. Thank you! – Isaac Nov 01 '13 at 11:57

0 Answers0