Stack Overflow archive
1 scoreaccepted

Android: How to change the colour of menu icons

score
1
question views
98
license
CC BY-SA 3.0

On phone, will improve later. This should work:

java
MenuItem menuItem = menu.findItem(R.id.your_menu_item);
Drawable drawable = menuItem.getIcon();
if (drawable != null) {
    // If we don't mutate the drawable, then all drawable's with this id will have a color
    // filter applied to it.
    drawable.mutate();
    drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    drawable.setAlpha(alpha);
}

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.