From google material design documentation.

On/off switches toggle the state of a single settings option. The option that the switch controls, as well as the state it’s in, should be made clear from the corresponding inline label. Switches take on the same visual properties of the radio button.

The on/off slide toggle with the text “on” and “off” included within the asset is deprecated. Use the switch shown here instead.

How to add?

I. In your build.gradle add latest appcompat library.

dependencies {  
    compile 'com.android.support:appcompat-v7:X.X.X' // where X.X.X version

II. Make your activity extend android.support.v7.app.AppCompatActivity.

public class MainActivity extends AppCompatActivity {  

III. Declare your SwitchCompat inside any layout.xml file


SwitchCompat is a backward compatible version of the Switch widget.

How to style?

I. Declare custom style in your styles.xml file.

<style name="MySwitch" parent="Theme.AppCompat.Light">  
    <!-- active thumb & track color (30% transparency) -->
    <item name="colorControlActivated">@color/indigo</item>

    <!-- inactive thumb color -->
    <item name="colorSwitchThumbNormal">@color/pink</item>

    <!-- inactive track color (30% transparency) -->
    <item name="android:colorForeground">@color/grey</item>

II. Apply this style to your SwitchCompat via android:theme attribute.


Android automatically add 30% transparency to colorControlActivated and android:colorForeground for SwitchCompat.