如何在关闭模式下更改开关项目的背景颜色?
答
设置的开关背景的颜色
创建的可绘制文件switch_track.xml用于开关背景
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/background_color_checked"
android:state_checked="true" />
<item android:color="@color/background_color_not_checked"/>
</selector>
创建的可绘制文件switch_thumb.xml用于开关thumb
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/thumb_color_checked"
android:state_checked="true" />
<item android:color="@color/thumb_color_not_checked"/>
</selector>
创建一个样式交换机
<style name="myCustomStyle" >
<item name="thumbTint">@drawable/switch_thumb</item>
<item name="trackTint">@drawable/switch_track</item>
</style>
,你可以申请到交换机上
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/myCustomStyle" />
它没有帮助,我需要改变的背景时,它的关闭 –