Philipp Redeker
Philipp Redeker

Reputation: 3878

How to change the TextColor auf ActionBarCompat MenuItem at runtime?

I need to change the TextColor of the MenuItems in my ActionBarCompat at runtime. Is there any way to do this?

Upvotes: 1

Views: 277

Answers (1)

Shivanand Darur
Shivanand Darur

Reputation: 3224

Try to use the spannable string to change the text of the menu item. here is the sample code for ur reference.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menuId, menu);
SpannableString str = new SpannableString("Menu item text");
str.setSpan(new ForegroundColorSpan(Color.BLUE), 0, str.length(), 0);
menu.getItem(R.id.menuItemId).setTitle(str);
}

Upvotes: 1

Related Questions