美文网首页
Android style妙用

Android style妙用

作者: doubimonkey | 来源:发表于2017-06-06 19:08 被阅读0次

checkbox 实现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应用这个style,大功告成~~

    <CheckBox
               style="@style/SwitchCheckboxTheme"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               />

相关文章

网友评论

      本文标题:Android style妙用

      本文链接:https://www.haomeiwen.com/subject/zbdnfxtx.html