Android Swtich开关样式调整
接入百度人脸的demo时候,发现了内置的switch开关比较好看,看了下实现方法,原来只是改了下样式,记录一下
效果:
代码
<Switch
android:id="@+id/announcements_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:textOff=""
android:textOn=""
android:checked="false"
android:thumb="@drawable/setting_switch_thumb"
android:track="@drawable/setting_switch_track_selector" />
setting_switch_thumb
:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#FFF" />
<stroke
android:width="3dp"
android:color="#00000000" />
<size
android:width="20dp"
android:height="20dp" />
</shape>
setting_switch_track_selector
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/setting_switch_track_on" android:state_checked="true" />
<item android:drawable="@drawable/setting_switch_track_off" android:state_checked="false" />
</selector>
setting_switch_track_on
和setting_switch_track_off
只是颜色不同,setting_switch_track_off
就不写了
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00BAF2" />
<corners android:radius="20dp" />
</shape>