'Android imageview tint

While setting tint for an ImageView in xml, I am getting a warning that shows:-

Must use app:tint instead of android:tint

Why should I use app:tint?



Solution 1:[1]

Because there were some issues where android:tint wasn't working for version < 21. app:tint works under version 21. Here is a similar problem. Drawable tinting for api <21

Solution 2:[2]

In AppCompatImageView it's fine, you could use android:tint.

Solution 3:[3]

ImageViewTintDetector lint check was added in androidx.appcompat:appcompat:1.2.0-alpha02 Add Lint rule to check android:tint usage on ImageView

Actually I have not found explanation why should developer replace android:tint with app:tint. My project minSdkVersion is 22.

Solution 4:[4]

It looks like this is a bug of Android Studio to me, as it doesn't take into account your minSdkVersion and also app:tint is not supported well in designer preview. It confuse and slow me repeatedly as I don't remember stuff like this when going back to android development.

Hopefully one day they will improve it to be really useful and account also your minSdkVersion but for now it look like its best to ignore that by going to preferences editor inspection and disable app:tint attribute should be used on completely.

Edit: Also I discovered that app:tint dont works on some android version so I am quite confused now I had to change all mistakenly set app:tint to android:tint

Solution 5:[5]

This looks like it's a bug. I have an XML with 3 ImageViews that are the exact same (they're copies of eachother), and I get that error in one of them only. Weirdly enough, clicking on Fix converts that line from android:tint="..." to card_view:tint="...".

Only solution so far was to add tools:ignore="UseAppTint" to silence this warning.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zankrut Parmar
Solution 2 Artem
Solution 3 user2051551
Solution 4
Solution 5 Ricardo Yubal