Question Detail

How to set tint for an image view programmatically in android?

6 years ago Views 12057 Visit Post Reply

I can set tint through XML but I  am not able to set it programmatically so please tell me how can I set tint Color programmatically.


Thread Reply

Anonymous

- 6 years ago

try this:

imageView.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.MULTIPLY);

its for me.

Correct Answer

Hemant Sharma

- 5 years ago

Programmatically Try : 

imageView.setColorFilter(Color.argb(245, 57, 57,5));


and

Try this in your XML file :

<ImageView
            android:id="@+id/image_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_user"
            android:tint="#ff0000"
            />