一、自定义CheckBox样式
*res/drawable文件夹下定义selector_checkbox.xml样式文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/checkbox_check" android:state_checked="true"/>
<item android:drawable="@mipmap/checkbox_normal" android:state_checked="false"/>
<item android:drawable="@mipmap/checkbox_normal"/>
</selector>
res/layout文件夹下xml文件中引用selector样式
<CheckBox
android:id="@+id/cb_stulogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="记住密码"
android:textColor="#ffffff"
android:textSize="12dp"
android:button="@drawable/checkbox_style"
android:paddingLeft="@dimen/stulogin_checkbox_padding"/>
注:paddingLeft用于设置CheckBox中选框和文字之间的距离
二、修改CheckBox颜色
res/values/colors.xml 文件中定义两种颜色
<color name="white">#ffffff</color>
<color name="inputbox_blue">#4b84b7</color>
res/values/styles.xml 文件中定义theme样式资源
<resources>
<style name="CheckBox" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">@color/white</item><!-- 未选中颜色 -->
<item name="colorControlActivated">@color/inputbox_blue</item><!-- 选中颜色 -->
</style>
</resources>
res/layout文件夹下xml文件中引用主题样式
<CheckBox
android:layout_width="@dimen/inputbox_width"
android:layout_height="wrap_content"
android:theme="@style/CheckBox"
android:checked="true"
android:text="@string/remember_customer"/>