您的位置:首页 > 移动开发 > Android开发

Android:Material Design之 Switch

2016-01-28 15:25 411 查看
开关

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;
}
}
}


/article/3637925.html

http://www.truiton.com/2015/03/android-switch-button-example/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: