android复选框教程,安卓使用selector定制复选框(checkbox)

效果图

4c4c75fc3834

未选中/选中状态

实现方案

增加选中状态下背景图:switch_selected.xml

android:width="32dp"

android:height="32dp"

android:viewportWidth="1024"

android:viewportHeight="1024">

android:fillColor="#FF8C00"

android:pathData="M512.1,960C271.5,960 76.5,765 76.5,524.5c0,-178.1 107,-331.2 260.3,-398.7l0.7,1.3c2.1,-0.5 4.3,-0.7 6.6,-0.7 17.2,0 31.1,14 31.1,31.1 0,7.6 -2.9,14.4 -7.4,19.9l1.4,2.3c-2.5,1 -5,2.3 -7.4,3.4 -2.8,2 -5.9,3.4 -9.2,4.3 -126.3,59.8 -213.7,188.3 -213.7,337.3C138.8,730.8 306,898 512.2,898s373.1,-167.4 373.1,-373.5c0,-139.9 -77.1,-261.5 -190.8,-325.4 -12,-4.3 -20.7,-15.7 -20.7,-29.2 0,-17.2 14,-31.1 31.1,-31.1 5.8,0 11.1,1.7 15.7,4.4l0.5,-0.8c134.9,74 226.4,217.2 226.4,382.1C947.6,765 752.6,960 512.1,960zM711.1,275.5c0,6.8 5.5,12.5 12.5,12.5 6.9,0 12.5,-5.5 12.5,-12.5s-5.5,-12.5 -12.5,-12.5 -12.5,5.7 -12.5,12.5zM512.1,835.6C340.3,835.6 201,696.3 201,524.5c0,-21.1 2.2,-41.7 6.1,-61.7l-22.9,-12.1c-5.3,23.8 -8.2,48.4 -8.2,73.7 0,185.5 150.4,335.9 335.9,335.9s335.9,-150.4 335.9,-335.9c0,-85.5 -32,-163.5 -84.6,-222.7l-15.7,20.1c46.9,54.4 75.3,125.1 75.3,202.6 0.2,171.9 -139,311.2 -310.7,311.2zM530.7,623.9c17.2,0 31.1,-14 31.1,-31.1L561.8,95.1c0,-17.2 -14,-31.1 -31.1,-31.1h-12.5c-17.2,0 -31.1,14 -31.1,31.1v497.8c0,17.2 14,31.1 31.1,31.1l12.5,-0.1z" />

增加未选中状态下背景图:switch_unselected.xml

android:width="32dp"

android:height="32dp"

android:viewportWidth="1024"

android:viewportHeight="1024">

android:fillColor="#DCDCDC"

android:pathData="M512.1,960C271.5,960 76.5,765 76.5,524.5c0,-178.1 107,-331.2 260.3,-398.7l0.7,1.3c2.1,-0.5 4.3,-0.7 6.6,-0.7 17.2,0 31.1,14 31.1,31.1 0,7.6 -2.9,14.4 -7.4,19.9l1.4,2.3c-2.5,1 -5,2.3 -7.4,3.4 -2.8,2 -5.9,3.4 -9.2,4.3 -126.3,59.8 -213.7,188.3 -213.7,337.3C138.8,730.8 306,898 512.2,898s373.1,-167.4 373.1,-373.5c0,-139.9 -77.1,-261.5 -190.8,-325.4 -12,-4.3 -20.7,-15.7 -20.7,-29.2 0,-17.2 14,-31.1 31.1,-31.1 5.8,0 11.1,1.7 15.7,4.4l0.5,-0.8c134.9,74 226.4,217.2 226.4,382.1C947.6,765 752.6,960 512.1,960zM711.1,275.5c0,6.8 5.5,12.5 12.5,12.5 6.9,0 12.5,-5.5 12.5,-12.5s-5.5,-12.5 -12.5,-12.5 -12.5,5.7 -12.5,12.5zM512.1,835.6C340.3,835.6 201,696.3 201,524.5c0,-21.1 2.2,-41.7 6.1,-61.7l-22.9,-12.1c-5.3,23.8 -8.2,48.4 -8.2,73.7 0,185.5 150.4,335.9 335.9,335.9s335.9,-150.4 335.9,-335.9c0,-85.5 -32,-163.5 -84.6,-222.7l-15.7,20.1c46.9,54.4 75.3,125.1 75.3,202.6 0.2,171.9 -139,311.2 -310.7,311.2zM530.7,623.9c17.2,0 31.1,-14 31.1,-31.1L561.8,95.1c0,-17.2 -14,-31.1 -31.1,-31.1h-12.5c-17.2,0 -31.1,14 -31.1,31.1v497.8c0,17.2 14,31.1 31.1,31.1l12.5,-0.1z" />

增加selector: switch_selector.xml

在checkbox中使用

android:button="@drawable/switch_selector"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

源代码

安卓发展历程及前景

初探安卓

开发语言学习

UI控件学习系列

关注头条号,第一时间获取最新文章:

4c4c75fc3834

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值