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.
(The definition of background for purposes of service limitations is distinct from the definition used by memory management; an app might be in the background as pertains to memory management, but in the foreground as pertains to its ability to launch services.) An app is considered to be in the foreground if any of the following is true:
For apps targeting Android 11 (API level 30), whenever Editor.clear is called, a callback is now made to OnSharedPreferenceChangeListener.onSharedPreferenceChanged with a null key. Android 11 includes updated lists of restricted non-SDK interfaces based on collaboration with Android developers and the latest internal testing.
Background Service Limitations. Services running in the background can consume device resources, potentially resulting in a worse user experience. To mitigate this problem, the system applies a number of limitations on services. The system distinguishes between foreground and background apps.
With Android 8.0, there is a complication; the system doesn't allow a background app to create a background service. For this reason, Android 8.0 introduces the new method startForegroundService() to start a new service in the foreground.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With