自定义chekBox 样式

来源:互联网 发布:震爆火箭炮升级数据 编辑:程序博客网 时间:2024/06/05 08:42

1、首先res/drawable中定义编写如下样式:

 

Java代码 
1.<?xml version="1.0" encoding="utf-8"?> 
2.<selector  xmlns:android="http://schemas.android.com/apk/res/android"> 
3.    <item android:drawable="@drawable/check_true" android:state_checked="true"></item> 
4.    <item android:drawable="@drawable/check_true" android:state_selected="true"></item> 
5.    <item android:drawable="@drawable/check_true" android:state_pressed="true"></item> 
6.    <item android:drawable="@drawable/check_false"></item> 
7.</selector> 
 
2、在layout中添加checkbox控件:

 

Java代码 
1.  
2.<CheckBox 
3.            android:id="@+id/radioButton1" 
4.            android:layout_width="wrap_content" 
5.            android:layout_height="wrap_content" 
6.            android:background="@drawable/btn_check" 
7.            android:button="@null" 
8.            android:checked="true"/> 
 
其中drwable/btn_check为1中顶一个文件名称,另外必须将android:button设置为@null。
@drawable/check_true和@drawable/check_false为checkbox不同状态的图片,可自行设计。

原创粉丝点击