31

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?

Kishor
  • 325
  • 1
  • 4
  • 6
  • Docs still mention `android:tint` instead of `app:tint`. Seems they should be updated. https://developer.android.com/reference/android/widget/ImageView#attr_android:tint – jack May 04 '21 at 21:43

5 Answers5

18

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

Zankrut Parmar
  • 1,872
  • 1
  • 13
  • 28
16

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

Artem
  • 896
  • 1
  • 11
  • 16
7

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.

user2051551
  • 167
  • 3
  • 10
2

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: For versions > 24 . Right now I bumped back into this, after reading somewhere that I should use app:tint for some possible compatibility issues I did that to my whole codebase. Then I realised that actually I have new issue after this change when tested on older devices so I reverted back to normal android:tint again.. issues where related to theme change that I do in my apps so somehow appcompat tint doesn't work the same as regular at last when I test in simulators form api 24 and my two more recent android devices, appcompat make actual issues regular works in my testing perfect so I hope I am not wrong with this.

Renetik
  • 5,887
  • 1
  • 47
  • 66
  • Which android versions? bdw, you can add tools:ignore="UseAppTint" to disable the warning. – Pitos Nov 26 '21 at 15:57
-1

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.

Ricardo Yubal
  • 374
  • 3
  • 8