How to Change Tint Color for an Image in Android

In this article, we will discuss how to change Tint Color for an Image in Android programmatically as well as in XML. Tint color means when we want to change the color of the image while rendering in ImageView. In XML is very easy to change tint color by just setting up the attribute android:tint="" in the ImageView tag, as shown in the following example.

Change Tint Color for an Image in Android

Set Tint Color in XML

<ImageView
     android:id="@+id/thumbnail_video_icon"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/YOUR_IMAGE"
     android:tint="#5089fa" />

Change Tint Color Programmatically in Android

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

JAVA

imageView.setColorFilter(getResources().getColor(R.color.YOUR_COLOR)); // Add tint color

To remove tint color again we can pass null as color filter. Like

imageView.setColorFilter(null); // Remove tint color

Kotlin

imageView.setColorFilter(resources.getColor(R.color.YOUR_COLOR)); // Add tint color
imageView.setColorFilter(null); // Remove tint color

That’s it. This how to change tint color for an Image in Android

Leave a Reply