I create a navigation box where the icon is colored depending on the color 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 facing is on this line, what am I passing to getColorStateList? Ocularization does not help me.
DrawableCompat.setTintList(drawable.mutate(),mContext.gerResouces.getColorStateList());
source
share