checkbox这个控件大家都不陌生,直接在xml文件里加个控件就可以了
<CheckBox android:id="@+id/check_image" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
无非就是改变复选框颜色大小,但原生UI效果不一定能满足我们设计师要求,需要自定义样式
步骤如下:
首先需要用android:button="@null"把原生复选框隐藏起来
然后准备两张 点击前后效果图
在res的drawable下建立一个shape文件 用来定义选中跟取消不同状态效果图
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/ckboxchecked" android:state_checked="true" /> <item android:drawable="@drawable/ckboxdis" />
</selector>
我们还可以定义渐变色