android checkbox自定义样式
16lz
2021-01-26
推荐安卓开发神器(里面有各种UI特效和android代码库实例)
1. 首先要导入你准备用作CheckBox选中和补选中状态的两图片到res的drawable中,如checkbox_checked.png,checkbox_normal.png;
2. 在res/drawable中添加checkbox.xml,定义checkbox的state list drawable图片
- <?xmlversion="1.0"encoding="UTF-8"?>
- <selectorxmlns:android="http://schemas.android.com/apk/res/android">
- <itemandroid:state_checked="true"android:drawable="@drawable/checkbox_checked"/><!--checked-->
- <itemandroid:state_checked="false"android:drawable="@drawable/checkbox_normal"/><!--default-->
- </selector>
复制代码
3. 在Layout中修改checkbox的属性:android:button="@drawable/checkbox" 定制button样式
- <CheckBoxandroid:layout_height="wrap_content"android:id="@+id/chkItem"android:button="@drawable/checkbox"></CheckBox>
这样就完成了定制工作,效果如下:
更多相关文章
- Android(安卓)爬坑路
- Android:自定义标题栏
- android中利用GPS获取位置信息的源码分析
- android Watchdog 实现剖析
- 对android:textAlignmentStyle 属性参数的理解
- 纯Java代码写登录注册页面
- Android(安卓)Gitlab CI/CD脚本
- android中所有颜色代码
- 接口 登录、注册、信息