checkbox 實現(xiàn)switch效果
原生的switch并不好看,自定義又很麻煩,如果大家不追求那個滑動的動畫效果的話,可以用我這個方法。
首先定義一個selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_check_open" android:state_checked="true" />
<item android:drawable="@drawable/icon_check_close" android:state_checked="false" />
<item android:drawable="@drawable/icon_check_close" />
</selector>
然后寫一個style
<style name="SwitchCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/switch_checkbox_selector</item>
</style>
最后把checkbox應(yīng)用這個style,大功告成~~
<CheckBox
style="@style/SwitchCheckboxTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>