1,修改颜色值
5.0 之后的CheckBox 会自带动画,我们只需要改变颜色值就可以实现我们的效果,不需要两张图了。
设置style:
<style name="CheckBox_Style_01" parent="@android:style/Widget.Material.CompoundButton.CheckBox" >
<item name="android:colorControlActivated">@color/colorPrimary</item> //选中的颜色
<item name="android:colorControlNormal">@color/gray</item>//默认的颜色
</style>
布局中引用这个style 就可以了:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/CheckBox_Style_01"
/>
但是这个style 必须是5.0+
所以我的最低版本是:
minSdkVersion 21
2,修改样式大小
默认的CheckBox 大小是固定的,可是现实的需求满足不了,比如需要CheckBox 小一点,那怎么设置呢,如下:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.8"
android:scaleY="0.8"
/>