Skip to content

Commit 72a0cec

Browse files
Material Design Teamhunterstich
authored andcommitted
[Docs] Updated Switch doc to make it more user friendly
PiperOrigin-RevId: 777433322
1 parent 84533b9 commit 72a0cec

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

docs/components/Switch.md

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,17 @@ path: /catalog/switches/
1010
# Switch
1111

1212
[Switches](https://m3.material.io/components/switch/overview) toggle the state
13-
of a single setting on or off. They are the preferred way to adjust settings on
14-
mobile devices.
15-
[Selection controls](https://m3.material.io/components/#selection) allow the
16-
user to select options.
13+
of a single setting on or off.
1714

1815
![White "Settings" menu with purple header and switches to turn on options, such
1916
as "Wi-fi" and "Bluetooth"](assets/switch/switch_hero.png)
2017

2118
**Note:** Images use various dynamic color schemes.
2219

23-
A `Switch` represents a button with two states, on and off. Switches are most
24-
often used on mobile devices to enable and disable options in an options menu. A
25-
switch consists of a track and thumb; the thumb moves along the track to
26-
indicate its current state.
27-
28-
Before you can use Material switches, you need to add a dependency on the
29-
Material components for Android library. For more information, go to the
30-
[Getting started](https://github.com/material-components/material-components-android/tree/master/docs/getting-started.md)
31-
page.
20+
Switches are best used to adjust settings and other standalone options. They
21+
make a binary selection, like on and off or true and false.
3222

33-
Use switch to:
34-
35-
* Toggle a single item on or off, on mobile and tablet
36-
* Immediately activate or deactivate something
37-
38-
**Note:** The `MaterialSwitch` widget provides a complete implementation of
39-
Material Design's switch component. It extends from the support library's
40-
`SwitchCompat` widget, but not from the framework `Switch` widget. As such, it
41-
does not auto-inflate, unlike other selection controls, and must be explicitly
42-
specified in layouts.
43-
44-
**Note:** For the old `SwitchMaterial` documentation, please refer to
45-
[Switch (deprecated)](#switch-deprecated) and
46-
[Theming switch (deprecated)](#theming-switch-deprecated).
23+
The effects of a switch should start immediately, without needing to save.
4724

4825
## Design & API documentation
4926

@@ -116,11 +93,9 @@ pressed. Rows are on or off](assets/switch/switch_states.png)
11693

11794
### Styles
11895

119-
Element | Style
120-
----------------- | ------------------------------------------------
121-
**Default style** | `Widget.Material3.CompoundButton.MaterialSwitch`
122-
123-
Default style theme attribute: `?attr/materialSwitchStyle`
96+
Element | Style | Theme attribute
97+
----------------- | ------------------------------------------------ | ---------------
98+
**Default style** | `Widget.Material3.CompoundButton.MaterialSwitch` | `?attr/materialSwitchStyle`
12499

125100
For the full list, see
126101
[styles](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/materialswitch/res/values/styles.xml)
@@ -129,6 +104,33 @@ and
129104

130105
## Code implementation
131106

107+
Before you can use Material switches, you need to add a dependency on the
108+
Material components for Android library. For more information, go to the
109+
[Getting started](https://github.com/material-components/material-components-android/tree/master/docs/getting-started.md)
110+
page.
111+
112+
**Note:** The `MaterialSwitch` widget provides a complete implementation of
113+
Material Design's switch component. It extends from the support library's
114+
`SwitchCompat` widget, but not from the framework `Switch` widget. As such, it
115+
does not auto-inflate, unlike other selection controls, and must be explicitly
116+
specified in layouts.
117+
118+
**Note:** For the old `SwitchMaterial` documentation, please refer to
119+
[Switch (deprecated)](#switch-deprecated) and
120+
[Theming switch (deprecated)](#theming-switch-deprecated).
121+
122+
### Adding switch
123+
124+
A `Switch` represents a button with two states, on and off. Switches are most
125+
often used on mobile devices to enable and disable options in an options menu. A
126+
switch consists of a track and thumb; the thumb moves along the track to
127+
indicate its current state.
128+
129+
Use switches to:
130+
131+
* Toggle a single item on or off
132+
* Immediately activate or deactivate something
133+
132134
The following example shows a list of five switches.
133135

134136
<img src="assets/switch/switch_example.png" alt="Example of 5 switches, the first one is toggled and the last one is disabled." height="350"/>
@@ -172,7 +174,7 @@ materialSwitch.setOnCheckedChangeListener { buttonView, isChecked
172174
}
173175
```
174176

175-
## Making switch accessible
177+
### Making switch accessible
176178

177179
Switches support content labeling for accessibility and are readable by most
178180
screen readers, such as Talkback. Text rendered in switches is automatically

0 commit comments

Comments
 (0)