您的位置:首页 > 移动开发 > Android开发

Android 自定义CheckBox复选框

2017-04-06 19:38 441 查看
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”设置复选框为空
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息