我有一个使用主题属性的状态列表颜色资源,即 button_background_tint.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorAccent" android:state_activated="true"/>
<item android:color="?android:attr/colorBackground"/>
</selector>
并使用
app:backgroundTint="@color/button_background_tint"
将其应用于我的 FloatingActionButton 背景色调该按钮在 API 21 或更高版本中看起来不错,但在 API 21 之下,无论其状态如何,背景都是红色的(即使
?android:attr/colorBackground
是 Theme.AppCompat.Light
的默认值)。有没有办法在 API 21 之前的颜色选择器中引用主题属性? (如果重要,请使用支持库 25.3.0)
最佳答案
?android:attr/colorBackground
在 API 21 之前没有定义。
使用 AndroidX 和 Material 组件时,您似乎可以使用 ?attr/colorSurface
因为它是相同的颜色。我猜您可以使用它来避免为 v21 及更高版本定义特定资源。
Material 成分的背景值和表面值均定义为 there .
关于android - 在 <API 21 中的颜色选择器中使用主题属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42823986/