开关
On/off 开关切换单一设置选择的状态。开关控制的选项以及它的状态,应该明确的展示出来并且与内部的标签相一致。开关应该单选按钮呈现相同的视觉特性。
开关通过动画来传达被聚焦和被按下的状态。
开关滑块上标明 “on” 和 “off” 的做法被弃用,取而代之的是下图所示的开关。
<android.support.v7.widget.SwitchCompat
android:id="@+id/sc_settin_testxinlv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="10dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
/>
public class SetActivity extends AppCompatActivity implements View.OnClickListener,
CompoundButton.OnCheckedChangeListener {
SwitchCompat switchCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
switchCompat = (SwitchCompat) findViewById(R.id
.sc_settin_testxinlv);
switchCompat.setSwitchPadding(40);
switchCompat.setOnCheckedChangeListener(this);
}
@Override
protected void onStop() {
super.onStop();
}
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
switch (compoundButton.getId()) {
case R.id.sc_settin_testxinlv:
break;
}
}
}
http://blog.csdn.net/ddwhan0123/article/details/50592579
http://www.truiton.com/2015/03/android-switch-button-example/