By itself, the Switch obeys only the theme Material Design, provided by the developer. Therefore, Google has made an element called SwitchCombat , which is more willing to comply with the requirements. Here is how it is created in the activity XML file:
... <android.support.v7.widget.SwitchCompat android:id="@+id/switch_compat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_marginLeft="50dp" android:checked="false" android:text="SwitchCompat" android:textOff="OFF" android:textOn="ON" app:showText="true"/> ...
To set the style for SwitchCombat , you first need to create the styles.xml and put lines like this into it:
<style name="MySwitch" parent="Theme.AppCompat.Light"> <item name="trackTint">@android:color/цвет</item> </style>
And, secondly, in the SwitchCombat itself register a link to the style:
<android.support.v7.widget.SwitchCompat ... android:theme="@style/MySwitch" />
You can also change the style for the active / inactive state, the color of the lane, etc. You can read more here .
PS At the request of the vehicle, I add a color change for the slider itself:
<style name="MySwitch" parent="Theme.AppCompat.Light"> ... <!-- Неактивное состояние --> <item name="colorSwitchThumbNormal">@android:color/цвет</item> <!-- Активное состояние --> <item name="colorControlActivated">@android:color/цвет</item> ... </style>