Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why backgroundTint requires android: prefix after API 21 but not before?

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.

like image 512
djnotes Avatar asked Feb 16 '18 11:02

djnotes


People also ask

When is an app considered to be in the background?

(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:

What's new in Android 11 (API level 30)?

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.

What are the limitations of background services in Android?

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.

Can a background app start a service in the foreground?

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.


2 Answers

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

like image 55
JorgeAmVF Avatar answered Oct 17 '22 07:10

JorgeAmVF


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.

like image 34
laalto Avatar answered Oct 17 '22 06:10

laalto