• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to change color of menu item icon in android?

I have the following menu item:

<item
android:id="@+id/icon_two"
android: orderInCategory="100"
android:icon="@android:drawable/ic_secure"
android:title="Secure Function"
app:showAsAction="ifRoom"
/>

but it's on black background and the ic_secure icon is black-ish and you can't really see it. I would like to make it white. Is that possible ? Or do I have to use another icon.. ?
 
Last edited:
The style attribute for the menu background is android:panelFullBackground. This can be changed in theme, which you apply to activity in manifest. Value of this attribute must be a resource, for example - @android:color/white , not a color value as #ffffff
Another solutions can be attributes android:itemBackground or android:actionBarItemBackground - depends what you want to change
 
Last edited:
Upvote 0
If you want to fill icon bitmap with color - return to old icon android:icon="@android:drawable/ic_secure" and try:
Java:
  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
// ... Your code
    Drawable drawable = menu.findItem(R.id.icon_two).getIcon();
        if (drawable != null) {
            drawable.mutate();
            drawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
     }
  }
Hope, this works
 
  • Like
Reactions: Bogdan Tudorascu
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones