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”设置复选框为空