开关
开关是调整设置的首选方式。它们用于控制二进制选项——比如开/关或真/假。
Interactive Demo
Playground
用法
开关可以是独立的或预选中的。
Playground
<md-switch aria-label="unchecked switch"></md-switch>
<md-switch aria-label="pre-checked switch" checked></md-switch>
图标
图标可用于在视觉上强调开关的选中状态。开关可以选择显示两个图标或仅显示选中的图标。
Playground
<md-switch icons></md-switch>
<md-switch icons checked></md-switch>
<md-switch icons checkedicononly></md-switch>
<md-switch icons checkedicononly checked></md-switch>
标签
使用 <label> 元素将标签与复选框关联。
Playground
<label>
Wi-Fi
<md-switch checked></md-switch>
</label>
<label for="switch-bluetooth">Bluetooth</label>
<md-switch id="switch-bluetooth"></md-switch>
无障碍
为没有标签的开关或需要更具描述性的标签的开关添加 aria-label 属性。
Playground
<md-switch aria-label="Lights"></md-switch>
<label>
All
<md-switch aria-label="All notifications"></md-switch>
</label>
注意:开关不会自动由 <label> 元素标记,始终需要 aria-label。
属性
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
icons | Boolean | false | 是否在开关滑块中显示图标。 |
checkedIconOnly | Boolean | false | 是否仅在选中时显示图标。 |