If I use setColorFilter like this, it works and paint my image with the chosen color:
int color = Color.parseColor("#FF0000");
viewHolder.Icon.setColorFilter(color);
But if I try to use a resource color, it does nothing:
viewHolder.Icon.setColorFilter(R.color.colorPrimary);
where the resource is defined like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FF5722</color>
</resources>
Answer marked as "right" use getColor() method which is deprecated. That's why here is up-to-date answer:
int color = ResourcesCompat.getColor(getResources(), R.color.my_color, null);
try this
int actionBarBackground = getResources().getColor(R.color.actionBarBackground);
and you set actionBarBackground in the method setColorFilter thats all
please add PorterDuff.Mode.MULTIPLY See below example
viewHolder.Icon.getDrawable().setColorFilter(getResources().getColor(R.color.blue), PorterDuff.Mode.MULTIPLY );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With