0

My styles

<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>

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>

But attribute android:activatedBackgroundIndicator is not worked. I need that with the active switch its thumb or track change without java code. Is it possible to do this?

0 Answers0