设置AppCompatCheckBox 选择框的颜色

Posted by Don on January 1, 2017

实现Material风格,项目中基本不在使用CheckBox而使用AppCompatCheckBox,设置其选择框的颜色方式如下:

在style.xml文件中添加如下代码:

    <style name="MyCheckBox" parent="Theme.AppCompat.Light">
        <item name="colorControlNormal">@android:color/white</item>
        <item name="colorControlActivated">@android:color/white</item>
    </style>

xml中的控件代码如下:

<android.support.v7.widget.AppCompatCheckBox
                    android:id="@+id/cb_f1"
                    android:layout_width="wrap_content"
                    android:layout_height="@dimen/height_48_default"
                    android:text="@string/F1"
                    android:onCheckedChanged="@{(cb,isChecked)->viewModel.onCheckedChanged(cb,isChecked)}"
                    android:checked="@{model.decorationMaterialsGrade==0?true:false}"
                    android:enabled="@{MyConfig.INFOPURVIEW_PERMS==permission?false:true}"
                    android:gravity="center_vertical"
                    android:layout_marginStart="@dimen/spacing_8_default"
                    android:textColor="@android:color/white"
                    android:theme="@style/MyCheckBox"
                    app:layout_constraintStart_toStartOf="@id/tv_hcho"
                    app:layout_constraintTop_toBottomOf="@id/tv_hcho"/>

效果图如下: