声明样式时,当我定义一个项目 android:backgroundTint
时,我收到一条警告,指出它从 API 21 开始可用,而我指定的最低 API 较低 (API 17)。另一方面,当我将其替换为简单的 backgroundTint
时,警告消失了。有谁知道这是为什么吗?
<!-- 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>
除此之外,如果我对单个组件(例如按钮)使用 android:backgroundTint
,无论我的项目的最低 SDK 是多少,我都不会收到任何警告或错误。这有点令人费解。
最佳答案
我知道这是一个老问题,但如果你关注 this solution指示我们将 android:backgroundTint
更改为 app:backgroundTint
,您将摆脱以下警告:
Attribute backgroundTint is only used in API level 21 and higher
关于android - 为什么 backgroundTint 需要 android : prefix after API 21 but not before?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48825405/