复选框默认样式与自定义样式


 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     android:layout_width="match_parent"
 3     android:layout_height="match_parent"
 4     android:padding="20dp">
 5     <TextView
 6         android:id="@+id/tv_wenti"
 7         android:layout_width="wrap_content"
 8         android:layout_height="wrap_content"
 9         android:text="你都会说什么?"
10         android:textSize="20sp"/>
11     <CheckBox
12         android:id="@+id/cb_1"
13         android:layout_width="wrap_content"
14         android:layout_height="wrap_content"
15         android:text="Nihao"
16         android:textSize="20sp"
17         android:layout_below="@+id/tv_wenti"
18         android:layout_marginTop="10dp" />
19 
20     <CheckBox
21         android:id="@+id/cb_2"
22         android:layout_width="wrap_content"
23         android:layout_height="wrap_content"
24         android:text="吃饭没"
25         android:textSize="20sp"
26         android:layout_below="@+id/cb_1"
27         android:layout_marginTop="10dp" />
28 
29     <CheckBox
30         android:id="@+id/cb_3"
31         android:layout_width="wrap_content"
32         android:layout_height="wrap_content"
33         android:text="睡觉吗"
34         android:textSize="20sp"
35         android:layout_below="@+id/cb_2"
36         android:layout_marginTop="10dp" />
37 
38     <LinearLayout
39         android:layout_width="match_parent"
40         android:layout_height="match_parent"
41         android:layout_marginTop="20dp"
42         android:layout_below="@id/cb_3"
43         android:orientation="vertical">
44         <TextView
45             android:id="@+id/tv_xingqu"
46             android:layout_width="wrap_content"
47             android:layout_height="wrap_content"
48             android:text="你的兴趣是什么"
49             android:textSize="20sp"
50             />
51         <CheckBox
52             android:id="@+id/cb_4"
53             android:layout_width="wrap_content"
54             android:layout_height="wrap_content"
55             android:text="抽烟"
56             android:button="@drawable/checkbox"
57             android:textSize="20sp"
58             android:layout_marginTop="10dp" />
59 
60         <CheckBox
61             android:id="@+id/cb_5"
62             android:layout_width="wrap_content"
63             android:layout_height="wrap_content"
64             android:text="喝酒"
65             android:button="@drawable/checkbox"
66             android:textSize="20sp"
67             android:layout_marginTop="10dp" />
68 
69         <CheckBox
70             android:id="@+id/cb_6"
71             android:layout_width="wrap_content"
72             android:layout_height="wrap_content"
73             android:text="烫头"
74             android:button="@drawable/checkbox"
75             android:textSize="20sp"
76             android:layout_marginTop="10dp"
77             android:paddingLeft="15dp"/>
78             
79     LinearLayout>
80 
81 RelativeLayout>

自定义样式可以是:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item  android:state_checked="true" android:drawable="@drawable/checkbox_true"/>
    <item  android:state_checked="false" android:drawable="@drawable/checkbox_false"/>
selector>

需要导入图标图片。