(1)在drawable文件夹下建立xml文件,文件名自定义
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/weixuanzhong2" android:state_checked="true"/> //选中后的选项,其余两个为未选中和默认的
<item android:drawable="@drawable/weixuanzhong" android:state_checked="false"/>
<item android:drawable="@drawable/weixuanzhong"/>
</selector>(2)在style文件里面加入如下:<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_style</item>
</style>(3)在布局文件引用即可:
style="@style/CustomCheckboxTheme"
本文介绍如何通过XML选择器实现自定义CheckBox的样式,并在样式文件中应用这些样式,最后在布局文件中引用。

412

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



