Reputation: 7247
I am making a navigation drawer where the icon is coloured based on the colour of the text.
This is my selector
declared in res/drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@color/emerald"/>
<item android:state_selected="true" android:color="@color/emerald"/>
<item android:state_pressed="true" android:color="@color/emerald"/>
<item android:color="@android:color/white"/>
</selector>
This is my ViewHolder
Drawable drawable = ContextCompat.getDrawable(mContext,iconResourceId);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTintList(drawable.mutate(),mContext.gerResouces.getColorStateList());
mItemIcon.setImageDrawable(drawable);
As you can see the problem i am having is on this line, what do i pass in getColorStateList
? The doucmentation is not helping me.
DrawableCompat.setTintList(drawable.mutate(),mContext.gerResouces.getColorStateList());
Upvotes: 23
Views: 15708
Reputation: 1798
ColorStateList colorStateList = ContextCompat.getColorStateList(this, R.color.your_color_selector);
snackBar.setActionTextColor(colorStateList);
Upvotes: 31
Reputation: 38595
Pass the id of the color state list resource, e.g. R.color.my_color_state_list
. Color state lists belong in res/color
, not res/drawable
.
DrawableCompat.setTintList(drawable.mutate(),
mContext.getResources().getColorStateList(R.color.my_color_state_list));
Upvotes: 24