如何使拇指开关时,开关活跃在android使用风格?

如何使拇指开关时,开关活跃在android使用风格?,android,android-layout,android-styles,Android,Android Layout,Android Styles,我的风格 <resources> <!-- Base application theme. --> <style name="myStyle" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item>

我的风格

<resources>

<!-- Base application theme. -->
<style name="myStyle" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:switchStyle">@style/mySwitch</item>
</style>

<style name="mySwitch" parent="android:Widget.Material.CompoundButton.Switch">
    <item name="android:track">@drawable/track</item>
    <item name="android:thumb">@drawable/thumb</item>
    <item name="android:switchPadding">10dp</item>
    <item name="android:textColor">#0B2AB9</item>
    <item name="android:textSize">16dp</item>
    <item name="android:thumbTint">#6E002472</item>
    <item name="android:thumbTintMode">src_atop</item>
    <item name="android:activatedBackgroundIndicator">@drawable/track</item>
</style>

</resources>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
@样式/mySwitch
@可牵引/轨道
@可牵引/拇指
10dp
#0B2AB9
16dp
#6E002472
src_顶部
@可牵引/轨道
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Switch
        android:id="@+id/turn"
        android:text="@string/turnon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="30dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>


但属性android:activatedBackgroundIndicator不起作用。我需要它与主动开关的拇指或轨道变化没有java代码。可以这样做吗?

Manoj Mohanty,这个问题没有直接的答案!什么属性或其他东西35; 46bdbf在您的交换机中使用此属性