tech74
tech74

Reputation: 1659

Tinting action bar icons with AppCompact v7 on Android

Is there an easy way of tinting the drawer icon, overflow menu icon and all action bar icons with a single theme color or do we need to color each icon separately. As mentioned in the title we are using Actionbar with support library compat v7 with SDK 21.

Thanks

Upvotes: 0

Views: 655

Answers (1)

voghDev
voghDev

Reputation: 5791

Maybe this solution works for ActionBar icons, should be valid for AppCompat too

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    MenuItem favoriteItem = menu.findItem(R.id.action_favorite);
    Drawable newIcon = (Drawable)favoriteItem.getIcon();
    newIcon.mutate().setColorFilter(getResources().getColor(R.color.myCustomTint), PorterDuff.Mode.SRC_IN);
    favoriteItem.setIcon(newIcon);
    return true;
}

More info on this question: Tint menu icons

Upvotes: 4

Related Questions