0

I am trying to change the color of a MenuItem from white to red permanently from fragment. In the fragmentselected (FragmentA) it changes color, but when I go to FragmentB it returns to white again. This is the code on fragmentselected

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    Drawable drawable=  menu.getItem(0).getIcon();
    drawable.setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP);

}
boris
  • 1
  • 4

1 Answers1

0

Add

Drawable drawable=  menu.getItem(0).getIcon();
drawable.setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP);

to onCreateOptionsMenu(Menu menu)

[UPDATE]

Add one line in your theme

<item name="android:actionMenuTextColor">@color/your_color</item>
Angus
  • 3,680
  • 1
  • 12
  • 27