Android 如何通过“设置chipBackgroundColor”;安卓:主题;具有AppCompat应用程序主题的属性
我有一个Android 如何通过“设置chipBackgroundColor”;安卓:主题;具有AppCompat应用程序主题的属性,android,themes,android-appcompat,material-components,android-chips,Android,Themes,Android Appcompat,Material Components,Android Chips,我有一个芯片组,它有一个芯片项目: <com.google.android.material.chip.ChipGroup android:id="@+id/chip_group" android:layout_width="0dp" android:theme="@style/DarkThemeTag" android:layout_height="wrap_content">
芯片组
,它有一个芯片
项目:
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group"
android:layout_width="0dp"
android:theme="@style/DarkThemeTag"
android:layout_height="wrap_content">
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/tag_text_dimen"
app:chipIcon="@null"
app:chipIconEnabled="false"/>
我的应用程序主题继承自AppCompat
,而不是MaterialComponents
:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
....
</style>
....
根据它继承自材料组件
。
表示应用程序的主题应继承自MaterialComponents
。
文章中提到,如果您无法将应用程序更改为继承自MaterialComponents
,并且您希望坚持使用AppCompat
,那么您应该使用桥接主题之一,所以我就是这么做的
问题在于chipBackgroundColor
属性不适用于芯片组的子级。然而,android:textColor
确实如此
你们知道怎么回事吗
注意:如果我在
芯片
元素上应用了相同的样式,它可以工作您应该在应用程序中使用桥接主题:
<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar.Bridge">
与:
与:
....
....
因为
chipBackgroundColor
中的默认选择器使用这些颜色。在应用程序中应用桥接主题!=在widget.com中使用android:theme。我不明白为什么芯片可以与AppCompat主题配合使用,但是当我尝试设置“chipBackgroundColor”属性时,它崩溃了。
<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar.Bridge">
<com.google.android.material.chip.ChipGroup
android:theme="@style/DarkThemeTag"
..>
<style name="DarkThemeTag" parent="">
<item name="android:textColor">@android:color/white</item>
</style>
<com.google.android.material.chip.Chip
style="@style/my_chip"
../>
<style name="my_chip" parent="@style/Widget.MaterialComponents.Chip.Action">
<item name="chipBackgroundColor">@color/tag_chip_dark_checkable</item>
</style>
<com.google.android.material.chip.Chip
app:chipBackgroundColor="....."
../>
<com.google.android.material.chip.Chip
android:theme="@style/custom_color"
../>
<style name="custom_color" parent="">
<item name="colorPrimary">....</item>
<item name="colorOnSurface">....</item>
</style>