Android 自定义CheckBox复选框
效果图
1.首先在drawable文件夹中添加drawable文件checkbox_style.xml。
在这里我是用了空心圆和实心圆图片,如果想换别的可以自行更改
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/yuan_f" android:state_checked="false"/> <item android:drawable="@drawable/yuan_t" android:state_checked="true"/> </selector>
2.在布局文件中使用background使用自定义checkbox样式。
<CheckBox android:visibility="gone" android:id="@+id/checkboxone" android:background="@drawable/selector" android:button="@null" android:layout_width="wrap_content" android:layout_height="wrap_content"/>在这里 Visibility属性详解主要用来设置控制控件的显示和隐藏。
详解可以参考:Android Visibility使用详解
android:button=“@null”设置复选框为空
本文介绍了如何在Android中自定义CheckBox复选框的样式。通过创建drawable资源文件`checkbox_style.xml`,利用选择器(Selector)实现空心圆和实心圆的效果,并在布局文件中设置`background`为该样式,同时将`button`设为`@null`来去除默认图标。
674

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



