自定义CheckBox

自定义android的CheckBox按钮图形有两个步骤三种方式:

 

第一步:

新建Android XML文件,类型选Drawable,根结点选selector,放置在drawable文件夹内,指定各种checked(甚至pressed)状态下的对应图片。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_checked="false" android:state_enabled="true" android:drawable="@drawable/checkbox"/>
    <item android:state_checked="true" android:state_enabled="true" android:drawable="@drawable/checkbox_checked"/>
    <item android:state_enabled="false" android:drawable="@drawable/checkbox_disable"/>
</selector>

 

第二步:

添加CheckBox控件,并选择下面三种方式中的一种进行配置:

  • 修改属性 android:button="@drawable/...(上面编写的xml)"

 

  • 编写style结点到style.xml,并添加到CheckBox属性 style="@style/xxx":

<style name="xxx" parent="@android:style/Widget.CompoundButton.CheckBox">
  <item name="android:button">@drawable/...(xml)</item>
</style>

 

  • 修改android:background="@drawable/...(xml)",并且 android:button="@null",将令复选框按钮图片直接衬托在文字下方。

 

 

转载于:https://www.cnblogs.com/wavky/p/3450699.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值