展会信息港展会大全

Android开发 自定义CheckBox 样式
来源:互联网   发布日期:2015-11-25 22:35:04   浏览:2313次  

导读:新建Android XML文件,类型选Drawable,根结点选selector,在这定义具体的样式。1?xmlversion=1.0encoding=UTF-8?2selectorxmlns:android=http://schemas.android.com/apk/res/android3itemandroid:s......

新建Android XML文件,类型选Drawable,根结点选selector,在这定义具体的样式。

1

<?xml version="1.0" encoding="UTF-8"?>

2

<selector xmlns:android="http://schemas.android.com/apk/res/android">

3

<item android:state_checked="true" android:state_pressed="true"

4

android:drawable="@drawable/focused" ;/>

5

<item android:state_checked="false" android:state_pressed="true"

6

android:drawable="@drawable/normal" ;/>

7

<item android:state_checked="false"android:drawable="@drawable/normal" ;/>

8

<item android:state_checked="true"android:drawable="@drawable/focused" ;/>

9

</selector>

state_checked 选中状态 state_pressed按下状态

即分别设置checkbox选中和没选中时,按下和没按下时显示的图片.

应用到Checkbox与Button不同,并不是设置Background属性,而是设置style属性,所以我们要写一个style。

在strings.xml写一个style,

1

<style name="MyCheckBox" parent="<a href="http://my.oschina.net/asia"class="referer" target="_blank">@android</a> :style/Widget.CompoundButton.CheckBox">

2

<item name="android:button">@drawable/checkbox</item>

3

;</style>

应用到Checkbox:

1

<CheckBox android:layout_width="wrap_content"

2

android:layout_height="wrap_content"

3

style="@style/MyCheckBox"

4

; />

赞助本站

人工智能实验室

相关热词: 自定义 CheckBox 样式

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港