but it changes the entire background of the switch not that small grey part. but it changes the entire background of the switch not that small grey part. but it changes the entire background of the switch not that small grey part.

Changing the background color of a Switch

243 Views Asked by At

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

1

There are 1 best solutions below

0
DIRTY DAVE On BEST ANSWER

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.