Android中自定义checkbox样式

1、首先res/drawable中定义编写如下样式:

<?xml version="1.0" encoding="utf-8"?>
<selector  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/check_true" android:state_checked="true"></item>
    <item android:drawable="@drawable/check_true" android:state_selected="true"></item>
    <item android:drawable="@drawable/check_true" android:state_pressed="true"></item>
    <item android:drawable="@drawable/check_false"></item>
</selector>


2、在layout中添加checkbox控件:

<CheckBox
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_check"
            android:button="@null"
            android:checked="true"/>

其中drwable/btn_check为1中顶一个文件名称,另外必须将android:button设置为@null。
@drawable/check_true和@drawable/check_false为checkbox不同状态的图片,可自行设计。

原文地址:https://www.cnblogs.com/zhujiabin/p/4729184.html