7

Declaring a style, when I define an item android:backgroundTint, I get a warning that this is available as of API 21 onward, while my minimum API specified is lower (API 17). On the other hand, when I replace that with simply backgroundTint, the warning is gone. Does anyone know why is that?

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:backgroundTint">#0F0</item>
</style>

Aside, from that, if I use android:backgroundTint for a single component, for example a button, I get no warning or error, no matter what my project's minimum SDK is. This is somewhat puzzling.

Mehdi Haghgoo
  • 3,144
  • 7
  • 46
  • 91
  • 2
    Cause `backgroundTint` introduced in API21 . Read [Here](https://developer.android.com/reference/android/view/View.html#attr_android:backgroundTint). So this Style belongs to style v-21 . And for warning i think this is happening because `backgroundTint` individually not an attribute so not getting compiled . – ADM Feb 16 '18 at 11:20

2 Answers2

6

I know it's an old question, but if you follow this solution that instructs us to change android:backgroundTint to app:backgroundTint, you get rid of the following warning:

Attribute backgroundTint is only used in API level 21 and higher

JorgeAmVF
  • 1,660
  • 3
  • 21
  • 32
  • 1
    Thanks for that! It indeed works with AppCompat activities or AppCompat views :) – xarlymg89 Jun 24 '19 at 15:04
  • Great to know it helped you, @xarlymg89! As it helped a lot while I was a looking for a similar question, I thought it could help others and it's good to know it was really useful for another developer. – JorgeAmVF Jun 25 '19 at 01:14
4

Why it works at runtime: AppCompat support library backports many of the later API level functionality and its styles define the prefix-free backgroundTint attribute.

Additional reason why lint does not complain: style attributes not prefixed with android: are not validated for known attribute names. You can actually put any string in item name attribute. For example:

<item name="iJustInventedThis">foo</item>

In layout widgets you get lint complaining about missing prefixes or unknown attributes. If you have an AppCompat widget such as AppCompatImageView, then you can use the backgroundTint attribute.

laalto
  • 150,114
  • 66
  • 286
  • 303
  • So, you can use any value for name in styles, but not for individual elements like Button, EditText, etc. As they need prefixes. Right? – Mehdi Haghgoo Feb 16 '18 at 11:41
  • In layout widgets you get lint complaining about missing prefixes or unknown attributes. – laalto Feb 16 '18 at 11:43
  • Might seem late, but your first paragraph raises my question. "... and its styles define the prefix-free backgroundTint attribute". Is that what you meant? I have a little problem understanding it. – Mehdi Haghgoo Jun 24 '19 at 17:23