I want to programmatically remove (reset) my ImageView Tint color which was already set in XML layout.
Asked
Active
Viewed 2.1k times
37
-
5try `imageview.setColorFilter(null);` – V-rund Puro-hit Jul 20 '17 at 04:14
-
19This question is NOT A DUPLICATE of the linked question and does not have an answer there (at the time of writing this comment). – talz Mar 25 '18 at 19:30
-
In older APIs you can use: https://developer.android.com/reference/android/support/v4/widget/ImageViewCompat#setimagetintlist passing null as the tintList – pandre Feb 07 '19 at 16:02
1 Answers
54
I think if above things doesn't works, you can try adding the image again to the imageview programatically, while adding it again programatically dont set tintcolor for it, it will be inflated with the original color
myImgView.setImageResource(R.drawable.yourDrwable);
or i think this should work for you.
imageview.setColorFilter(null)
or
imageView.clearColorFilter()
Uday Ramjiyani
- 1,357
- 8
- 21
-
6
-
3
-
8`imageView.drawable.setTintList(null)` to clear the tint. [Docs](https://developer.android.com/reference/android/graphics/drawable/Drawable#setTintList(android.content.res.ColorStateList)): `Color state list to use for tinting this drawable, or null to clear the tint This value may be null.` – Fatih Jul 20 '20 at 17:32
-
I had used app:tint= in xml and clearColorFilter and colorFilter = null didn't work. But .drawable.setTintList(null) worked if it was done after the drawable had been set to the ImageView. – Warpzit Sep 03 '20 at 10:52
-
7
-
@RRGT19 thanks! using ImageViewCompat is the only way that works for me – konnovdev May 20 '22 at 06:47