I am trying to change menu item text color dynamically.
I have a solution that works for menu icons, it uses the color filter as follows:
Drawable drawable = menuItem.getIcon();
if (drawable != null) {
drawable.mutate();
drawable.setColorFilter(new
PorterDuffColorFilter(Color.parseColor(color), PorterDuff.Mode.MULTIPLY));
}
menuItem.setIcon(drawable);
I am unable to change the color of menu item text. To make this work I used the following code:
SpannableString s = new SpannableString(menuItem.getTitle());
s.setSpan(new ForegroundColorSpan(Color.parseColor(color)), 0, s.length(), 0);
menuItem.setTitle(s);
the color of "SAVE" is what I am trying to change.
Can anyone help me out with this?