For @DjimOnDev. I'm using this
Switch sw = new Switch(getActivity());
sw.setGravity(Gravity.RIGHT|Gravity.CENTER_VERTICAL);
sw.setTextOn(getString(R.string.ok));
sw.setTextOff(getString(R.string.remove));
if (sw.isChecked()) {
sw.setSwitchTextAppearance(getActivity(), R.style.SwitchTextAppearance1);
}
else {
sw.setSwitchTextAppearance(getActivity(), R.style.SwitchTextAppearance2);
}
sw.setSwitchMinWidth((int) (3.6 * pixels));
sw.setThumbResource(R.drawable.thumb);
sw.setTrackResource(R.drawable.track);
sw.setSwitchTypeface(font);
thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#bfb5a7" />
</shape>
track.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/thumb_off" />
<item android:drawable="@drawable/thumb_default" />
styles.xml
<style name="SwitchTextAppearance1">
<item name="android:textColor">#5db701</item>
</style>
<style name="SwitchTextAppearance2">
<item name="android:textColor">#ea3d3d</item>
</style>