原文地址:https://www.cnblogs.com/Claire6649/p/5941145.html
1.首先在drawable文件夹中添加drawable文件checkbox_style.xml。

1 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
2 <item
3 android:drawable="@drawable/sel_check"
4 android:state_checked="true"/>
5 <item
6 android:drawable="@drawable/sel_nor"
7 android:state_checked="false"/>
8 <item
9 android:drawable="@drawable/sel_nor"/>
10
11 </selector>

2.在values文件夹下的styles.xml文件中添加CustomCheckboxTheme样式。
1 <!-- CustomCheckBox theme -->
2 <style name="CustomCheckBoxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
3 <item name="android:button">@drawable/checkbox_style</item>
4 </style>
3.在布局文件中使用CustomCheckBoxTheme样式。

1 <CheckBox
2 android:id="@+id/tv_upper"
3 android:layout_width="wrap_content"
4 android:layout_height="wrap_content"
5 android:gravity="center_vertical"
6 style="@style/CustomCheckBoxTheme" />

使用到的图片资源
sel_check.png
sel_nor.png
本文介绍如何在Android应用中创建自定义样式的CheckBox组件。通过在XML文件中定义选择器和样式,可以改变CheckBox选中和未选中状态的外观。布局文件中应用这些样式以实现统一的设计风格。
434

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



