2017-12-27 179 views

回答

1

设置的开关背景的颜色

创建的可绘制文件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" /> 
1

首先添加一些代码或任何你已经尝试过,所以我们可以帮你。

第二个这里是一些定制android中的开关的教程。

Link 1Link 2

+1

它没有帮助,我需要改变的背景时,它的关闭 –