Search code examples
androidandroid-switch

Changing the background color of a Switch


enter image description here

I've tried using android:background="@color/colorWhite"/> but it changes the entire background of the switch not that small grey part.

<androidx.appcompat.widget.SwitchCompat
          
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_marginEnd="16dp"
            android:layout_centerVertical="true"
            android:background="@color/colorWhite"/>

enter image description here

android:backgroundTint doesn't do anything either


Solution

  • The background is called a track and you can change the color of it by using

    app:trackTint="@color/darkThemeGreyTextColor"

    The "button" is called a thumb and you can change the color of it with

    app:thumbTint="@color/heartRed"

    I didn't see these attributes because I was using the android: prefix instead of the app: prefix to see the available options.