XML基本属性:
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="关"
android:textOff="开"
android:switchMinWidth="40dp"
android:track="@drawable/switch_track"
android:thumb="@android:color/transparent" />
监听:
mSwitch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
//Todo
}else {
//Todo
}
}
});