Georgi Stoyanov Georgi Stoyanov - 11 months ago 88
Android Question

Tinting ImageView not working on Android 5.0. Ideas how to make it work again?

In an application I've built I noticed that the ImageViews are not tinted on devices running the new Android Lollipop. This is the code that used to work correctly on older versions of the OS:

android:tint="@color/intent_circle_green_grey" />

and this is the drawable that is loaded in the ImageView:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="" android:shape="oval" >
<gradient android:startColor="@color/white" android:endColor="@color/white"

Once again, this is working correctly on devices running JellyBean/Kitkat, but the tint has no effect on devices running Lollipop. Any ideas how to fix it? Is it a bug in the OS, or should I start tinting the image differently?

Answer Source

As per @alanv comment, here goes the hacky fix to this bug. Basic idea is to extend ImageView and apply ColorFilter right after inflation:

public class TintImageView extends ImageView {

    public TintImageView(Context context, AttributeSet attrs) {
        super(context, attrs);


    private void initView() {
            ColorStateList imageTintList = getImageTintList();
            if (imageTintList == null) {

            setColorFilter(imageTintList.getDefaultColor(), PorterDuff.Mode.SRC_IN);

As you might guess, this example is somewhat limited (Drawable set after inflation tint won't be updated, only default color of ColorStateList is used, and maybe something else), but if you got the idea you can fit it to your use-case.