转载自:http://www.open-open.com/lib/view/open1392187282067.html
有些时候需要根据项目需求自定义CheckBox 的样式,步骤如下:
1.首先在drawable文件夹中添加drawable文件my_checkbox.xml
2.在values文件夹下的styles.xml文件中添加CustomCheckboxTheme样式
1
2
3
|
<
style
name
=
"custom_checkbox"
parent
=
"@android:style/Widget.CompoundButton.CheckBox"
>
<
item
name
=
"android:button"
>@drawable/my_checkbox</
item
>
</
style
>
|
3.在CheckBox中使用CustomCheckboxTheme样式
1
2
3
4
5
6
7
|
<
CheckBox
android:id
=
"@+id/checked"
style
=
"@style/custom_checkbox"
android:layout_width
=
"40dip"
android:layout_height
=
"wrap_content"
android:layout_marginLeft
=
"10dip"
android:checked
=
"false"
/>
|
使用的图片资源
checkbox_normal.png 未选中状态图片
checkbox_pressed.png 选中状态图片