这是我的代码,但对我来说并不适用。 我使用this示例中的代码。
Xml -
<android.support.v7.widget.SwitchCompat
android:id="@+id/visibility_switch"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_marginRight="@dimen/mat_card_padding"
app:showText="false" />
代码:
mVisibilitySwitchCompat = (SwitchCompat) findViewById(R.id.visibility_switch);
mVisibilitySwitchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// this method doesn't work!
if (isChecked) {
mVisibilityTextView.setText(getString(R.string.visibility_on));
} else {
mVisibilityTextView.setText(getString(R.string.visibility_off));
}
}
});