Issue
I am using DrawableCompat
and setTint
to change the color of one of my Drawable
s and setting its color to white.
I'm using this code in my onCreateOptionsMenu
:
Drawable mDrawable = ContextCompat.getDrawable(this,R.drawable.ic_add_circle_outline_black_24dp);
mDrawable = DrawableCompat.wrap(mDrawable);
DrawableCompat.setTint(mDrawable, Color.RED);
menu.findItem(R.id.item_addnew).setIcon(mDrawable);
but the Drawable
remains black. Am I using the DrawableCompat
in a wrong way?
Solution
For some mysterious reason, setting the black icon as default in the XML of my Menu
and using Menu.getIcon()
to retrieve the Drawable
did the trick:
Drawable mDrawable = menu.findItem(R.id.item_addnew).getIcon();
mDrawable = DrawableCompat.wrap(mDrawable);
DrawableCompat.setTint(mDrawable, Color.WHITE);
menu.findItem(R.id.item_addnew).setIcon(mDrawable);
Answered By - Vektor88
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.