如何自定义CheckBox多选框的样式
来源:互联网 发布:网络棋牌赌博犯法吗 编辑:程序博客网 时间:2024/05/22 13:52
安卓自带的CheckBox有时候不能满足项目需求,这时候就需要自己定制一套样式出来。具体实现方法如下:
第一:首先需要找几张自己想要定义成的图片:
把上面的图片放到drawable-xhdpi或者mipmap目录下。
第二:在res目录下面创建drawable文件夹,drawable下面创建xml文件checkbox_selector.xml代码如下:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_checked="false" android:state_pressed="true" android:drawable="@drawable/grid_check_off_press"></item> <item android:state_checked="false" android:drawable="@drawable/grid_check_off"></item> <item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/grid_check_on_press" /> <item android:state_checked="true" android:drawable="@drawable/grid_check_on"></item></selector>
到这里工作已经完成1/2了。
第三:在stytle文件中新建样式:
<style name="mycheckbox" parent="@android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/checkbox_selectors</item> <item name="android:paddingLeft">10.0dip</item> <item name="android:height">35.0dip</item></style>
第四:在布局中使用就好啦,引入stytle样式。
<CheckBox android:id="@+id/checkBox1" style="@style/mycheckbox" android:layout_width="wrap_content" android:layout_height="35dp" android:layout_alignLeft="@+id/tv" android:layout_below="@+id/tv" android:layout_marginTop="84dp" android:text="自定义样式" />
点此下载源码
0 0
- 如何自定义CheckBox多选框的样式
- 如何自定义checkbox的样式
- 自定义样式的checkBox
- 自定义checkbox的样式
- 自定义input checkBox的样式
- android 自定义checkBox的样式
- Android自定义样式的Checkbox
- 用WPF自定义CheckBox的样式
- android 自定义CheckBox的外观样式
- 自定义RadioButton&CheckBox样式的实现
- 自定义CheckBox的选中与否样式
- android checkbox设置自定义的样式
- 自定义CheckBox和RadioButton的样式
- 自定义radio与checkbox的样式
- 自定义checkbox选择框的样式
- 自定义RadioButton&CheckBox样式的实现
- checkbox兼容主流浏览器的自定义样式
- 自定义checkbox和radio的样式
- python学习笔记
- c# 使用GDI绘制验证码实例
- 2016.08.30回顾
- Spark2.0机器学习系列之6: MLPC(多层神经网络)
- Enhancing Android UI with Custom Views 通过自定义view来让你的UI更屌!
- 如何自定义CheckBox多选框的样式
- JAVA Script 之Jquery初步学习,入门学习,jquery基础,浅谈其基本用法。
- 终于有人把大数据、红海、蓝海、众筹说清楚了 (太简单粗暴了!)
- 基础笔试(1)
- 深入浅出struts2
- c++ 动态DLL编写和使用
- commos configuration 获得xml,properties 的属性
- linux 安装 php- soap
- common-lang包中一些工具类的使用说明