<CheckBox
android:id="@+id/checkBox"
style="@style/mystyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="15dp"
android:focusable="false" >
</CheckBox>
mycheck_selection.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="@drawable/checkbox_tick" /><!--选中时效果-->
<item android:state_checked="false"
android:drawable="@drawable/checkbox" /><!--未选中时效果-->
<!-- 修改成你自己的图片就可以了 -->
</selector>
style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="mystyle" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/mycheck_selection</item>
<item name="android:paddingLeft">25.0dip</item>
<item name="android:maxHeight">10.0dip</item>
</style>
</resources>
本文介绍如何在Android应用中自定义CheckBox的样式,包括选中和未选中状态的不同显示效果。通过XML文件定义选择器,并在style文件中指定CheckBox的样式属性。
2万+

被折叠的 条评论
为什么被折叠?



