I created switch in code, not in xml.
Switch sw = new Switch(getActivity());
sw.setGravity(Gravity.RIGHT|Gravity.CENTER_VERTICAL);
sw.setTextOn(getString(R.string.ok));
sw.setTextOff(getString(R.string.remove));
sw.setSwitchMinWidth((int) (4.8 * pixels));
sw.setSwitchTypeface(font);
sw.setThumbResource(R.drawable.thumb);
Method setThumbResource is working well, but the method setTrackResource leads to the disappearence of switch.
My xml files for thumb and for track. They are almost the same.
thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<solid android:color="#a79d90" />
</shape>
track.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<solid android:color="#bfb5a7" />
</shape>
Also, what I want to do is to set different colors for TextOn (green) and TextOff (red). I found only one method - setTextColor that leads to changing both colors.