Reputation: 355
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?
Upvotes: 34
Views: 14537
Reputation: 6373
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.
Upvotes: 2
Reputation: 491
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.
Upvotes: 2
Reputation: 227
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.
Upvotes: 8
Reputation: 1997
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
Upvotes: 20