thumbTint为指示头颜色
<Switch
android:id="@+id/send_switch"
android:layout_marginLeft="10dp"
android:trackTint="@color/text_hint"
android:thumbTint="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
代码控制滑道颜色
sendSwitch = (Switch) findViewById(R.id.send_switch);
sendSwitch.setTrackResource(R.mipmap.switch_gray);
sendSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
urgency = 1;
sendSwitch.setTrackResource(R.mipmap.switch_blue);
} else {
urgency = 0;
sendSwitch.setTrackResource(R.mipmap.switch_gray);
}
}
});