Android 禁用时更改开关颜色

Android 禁用时更改开关颜色,android,material-design,Android,Material Design,我有一个开关,当它被启用和选中时,它的颜色就是我的主颜色 我想有相同的颜色时,它的检查,但禁用,我无法找到一种方法来完成它 我尝试使用选择器,但它改变了开关背景,而不是切换本身 如何更改开关颜色的切换 谢谢。1-在styles.xml中使用此选项 <style name="SwitchStyle" parent="Theme.AppCompat.Light"> <item name="colorControlActivated">@color/theme&l

我有一个开关,当它被启用和选中时,它的颜色就是我的主颜色

我想有相同的颜色时,它的检查,但禁用,我无法找到一种方法来完成它

我尝试使用选择器,但它改变了开关背景,而不是切换本身

如何更改开关颜色的切换


谢谢。

1-在styles.xml中使用此选项

 <style name="SwitchStyle" parent="Theme.AppCompat.Light">
      <item name="colorControlActivated">@color/theme</item>
      <item name="colorSwitchThumbNormal">@color/grey300</item>
      <item name="android:colorForeground">@color/grey600</item>
</style>

@颜色/主题
@颜色/灰色300
@颜色/灰色600
然后,这是您的交换机:

<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/SwitchStyle" />

双开关:

<Switch
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/selector.xml" />

selector.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:drawable="@drawable/on" android:state_checked="true"/> 
     <item android:drawable="@drawable/off" android:state_checked="false"/>
 </selector>


我已更新我的帖子重试第一个解决方案如果不起作用,请尝试第二个解决方案@SharascolorSwitchThumbNormal在正常状态下不起作用