Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何通过“设置chipBackgroundColor”;安卓:主题;具有AppCompat应用程序主题的属性_Android_Themes_Android Appcompat_Material Components_Android Chips - Fatal编程技术网

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>