Appcompat v7 Material 复选框在 Lollipop 设备中将颜色更改为默认黑色

Appcompat v7 Material checkbox changing color to default black in Lollipop devices

我正在使用 appcompat v7 material 复选框。我的项目主题是浅蓝色,所以我在 styles.xml 中为我的复选框选中颜色分配浅蓝色,如下所示

<!--checked color-->
<item name="colorAccent">@color/light_blue</item> 

<!--un checked color--> 
<item name="android:textColorSecondary">@color/secondary_text</item>  

在我的布局文件中

    <CheckBox
        android:id="@+id/chk_tick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@drawable/abc_btn_check_material"
        android:layout_gravity="center"/>

kitkat 以下版本一切正常,但问题仅出现在棒棒糖版本(默认情况下它会自动分配黑色)。我真的不知道为什么会这样。请帮助我解决您的问题。提前致谢

删除这一行:

android:button="@drawable/abc_btn_check_material"

您的 CheckBox 应自动设置样式,无需设置 android:button 属性。

使用 AppCombat 复选框以获得最佳结果

<android.support.v7.widget.AppCompatCheckBox
    android:id="@+id/chkSelected"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/white"
   />

之后转到 styles.xml 并按如下方式创建新样式

   <style name="SampleTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="colorAccent">@color/colorAccent</item>
            <item name="android:textColorSecondary">@color/red</item>
        </style>

这还没有完成去你的清单xml

 <activity
        android:name=".yourActivity"
        android:theme="@style/SampleTheme" /> 

这也适用于 pre_lollipop 设备。编码愉快:)