Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

<ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="bottom|right"
            android:contentDescription="@string/descr_background_image"
            android:src="@drawable/circle_shape_white_color"
            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="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <gradient android:startColor="@color/white" android:endColor="@color/white"
        android:angle="270"/>
</shape>

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?

like image 542
Georgi Stoyanov Avatar asked Nov 27 '14 16:11

Georgi Stoyanov


People also ask

Can I change image color Android studio?

We can change the color of an image programmatically in Android using the following setColorFilter method through the ImageView reference object.


1 Answers

Use the AppCompatImageView like so:

<android.support.v7.widget.AppCompatImageView
        android:id="@+id/my_appcompat_imageview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/my_image"
        android:tint="#636363"
    />

Make sure you have the latest compile 'com.android.support:appcompat-v7:23.4.0' in your app's build.gradle.

like image 187
Alireza Ghanbarinia Avatar answered Sep 28 '22 09:09

Alireza Ghanbarinia