首页 > 移动平台 > 详细

Android之自定义checkbox样式

时间:2016-05-06 21:46:05      阅读:168      评论:0      收藏:0      [点我收藏+]

大部分情况下,我们在UI中并不采用Android自带的checkbox复选框样式,这时候就需要我们自定义自己的checkbox。

 

首先找两张checkbox背景图片,比如下图样子的:

技术分享

然后在drawable目录下定义一个背景图片xml文件,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/fuxuan_input01" />
    <item android:state_selected="true" android:drawable="@drawable/fuxuan_input01"></item>
    <item android:state_pressed="true" android:drawable="@drawable/fuxuan_input01"></item>
    <item android:state_checked="false" android:drawable="@drawable/fuxuan_input02" />
</selector>

在需要用到checkbox的地方定义它,属性设置如下代码所示:

        <CheckBox
            android:id="@+id/agree_provision_chk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/chk_agee_provision_background"
            android:button="@null" />

自定义checkbox就此完成,效果如下图所示:

 

技术分享

 

Android之自定义checkbox样式

原文:http://www.cnblogs.com/zhujiabin/p/5467129.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!