Skip to content

Commit cfb541e

Browse files
Material Design Teamdrchen
authored andcommitted
[Docs] Updated Checkbox doc to make it more user friendly.
PiperOrigin-RevId: 777888406
1 parent b1e90f5 commit cfb541e

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

docs/components/Checkbox.md

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,13 @@ path: /catalog/checkboxes/
1212
[Checkboxes](https://m3.material.io/components/checkbox/overview) let users
1313
select one or more items from a list, or turn an item on or off.
1414

15-
<img src="assets/checkbox/checkbox_hero.png" alt="Checkbox hero: Meal options" header, "Additions" checkbox, "Pickles" "Lettuce" "Tomato" checkboxes with “Lettuce” checked" width="800">
15+
<img src="assets/checkbox/checkbox_hero.png" alt="Checkbox hero: Meal options" header, "Additions" checkbox, "Pickles" "Lettuce" "Tomato" checkboxes with “Lettuce” checked" width="900">
1616

1717
**Note:** Images use various dynamic color schemes.
1818

19-
Before you can use Material checkboxes, you need to add a dependency to the
20-
Material components for Android library. For more information, go to the
21-
[Getting started](https://github.com/material-components/material-components-android/tree/master/docs/getting-started.md)
22-
page.
23-
24-
```xml
25-
<CheckBox
26-
android:layout_width="match_parent"
27-
android:layout_height="wrap_content"
28-
android:text="@string/label"/>
29-
```
30-
31-
**Note:** `<CheckBox>` is auto-inflated as
32-
`<com.google.android.material.button.MaterialCheckBox>` via
33-
`MaterialComponentsViewInflater` when using a `Theme.Material3.*`
34-
theme.
35-
3619
## Design & API documentation
3720

38-
* [Material 3 (M3) spec] (https://m3.material.io/components/checkbox/overview)
21+
* [Material 3 (M3) spec](https://m3.material.io/components/checkbox/overview)
3922
* [API reference](https://developer.android.com/reference/com/google/android/material/checkbox/package-summary)
4023

4124
## Anatomy
@@ -45,7 +28,8 @@ theme.
4528
1. Container
4629
2. Icon
4730

48-
More details on anatomy items in the [component guidelines](https://m3.material.io/components/checkbox/guidelines#c04665de-5bf3-4706-87ae-68ad7e2b7fda).
31+
More details on anatomy items in the
32+
[component guidelines](https://m3.material.io/components/checkbox/guidelines#c04665de-5bf3-4706-87ae-68ad7e2b7fda).
4933

5034
## Key properties
5135

@@ -54,13 +38,13 @@ More details on anatomy items in the [component guidelines](https://m3.material.
5438
The checkbox is composed of an `app:buttonCompat` drawable (the container) and
5539
an `app:buttonIcon` drawable (the icon) layered on top of it.
5640

57-
Element | Attribute | Related method(s) | Default value
58-
-------------------------- | ------------------------------------------ | ---------------------------------------------------------- | -------------
59-
**Button tint** | `app:buttonTint` | `setButtonTintList`<br/>`getButtonTintList` | `?attr/colorOnSurface` (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/checkbox/res/color/m3_checkbox_button_tint.xml))
60-
**Button icon drawable** | `app:buttonIcon` | `setButtonIconDrawable`<br/>`getButtonIconDrawable` | [@mtrl_checkbox_button_icon](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/checkbox/res/drawable/mtrl_checkbox_button_icon.xml)
61-
**Button icon tint** | `app:buttonIconTint` | `setButtonIconTintList`<br/>`getButtonIconTintList` | `?attr/colorOnPrimary` (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/checkbox/res/color/m3_checkbox_button_icon_tint.xml))
62-
**Min size** | `android:minWidth`<br/>`android:minHeight` | `(set/get)MinWidth`<br/>`(set/get)MinHeight` | `?attr/minTouchTargetSize`
63-
**Centered icon if no text** | `app:centerIfNoTextEnabled` | `setCenterIfNoTextEnabled`<br/>`isCenterIfNoTextEnabled` | `true`
41+
Element | Attribute | Related method(s) | Default value
42+
---------------------------- | ------------------------------------------ | -------------------------------------------------------- | -------------
43+
**Button tint** | `app:buttonTint` | `setButtonTintList`<br/>`getButtonTintList` | `?attr/colorOnSurface` (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/checkbox/res/color/m3_checkbox_button_tint.xml))
44+
**Button icon drawable** | `app:buttonIcon` | `setButtonIconDrawable`<br/>`getButtonIconDrawable` | [@mtrl_checkbox_button_icon](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/checkbox/res/drawable/mtrl_checkbox_button_icon.xml)
45+
**Button icon tint** | `app:buttonIconTint` | `setButtonIconTintList`<br/>`getButtonIconTintList` | `?attr/colorOnPrimary` (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/checkbox/res/color/m3_checkbox_button_icon_tint.xml))
46+
**Min size** | `android:minWidth`<br/>`android:minHeight` | `(set/get)MinWidth`<br/>`(set/get)MinHeight` | `?attr/minTouchTargetSize`
47+
**Centered icon if no text** | `app:centerIfNoTextEnabled` | `setCenterIfNoTextEnabled`<br/>`isCenterIfNoTextEnabled` | `true`
6448

6549
**Note:** If setting a custom `app:buttonCompat`, make sure to also set
6650
`app:buttonIcon` if an icon is desired. The checkbox does not support having a
@@ -90,11 +74,9 @@ error. Checkboxes have enabled, disabled, hover, focused, and pressed states.
9074

9175
### Styles
9276

93-
Element | Style
94-
----------------- | ---------------------------------------------------
95-
**Default style** | `Widget.Material3.CompoundButton.CheckBox`
96-
97-
Default style theme attribute: `?attr/checkboxStyle`
77+
Element | Style | Theme attribute
78+
----------------- | ------------------------------------------ | ---------------
79+
**Default style** | `Widget.Material3.CompoundButton.CheckBox` | `?attr/checkboxStyle`
9880

9981
For the full list, see
10082
[styles](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/checkbox/res/values/styles.xml)
@@ -103,6 +85,26 @@ and
10385

10486
## Code implementation
10587

88+
Before you can use Material checkboxes, you need to add a dependency to the
89+
Material components for Android library. For more information, go to the
90+
[Getting started](https://github.com/material-components/material-components-android/tree/master/docs/getting-started.md)
91+
page.
92+
93+
### Adding checkbox
94+
95+
```xml
96+
<CheckBox
97+
android:layout_width="match_parent"
98+
android:layout_height="wrap_content"
99+
android:text="@string/label"/>
100+
```
101+
102+
**Note:** `<CheckBox>` is auto-inflated as
103+
`<com.google.android.material.button.MaterialCheckBox>` via
104+
`MaterialComponentsViewInflater` when using a `Theme.Material3.*` theme.
105+
106+
### Checkbox example
107+
106108
The following example shows a list of checkboxes with a parent/children
107109
relationship.
108110

@@ -221,14 +223,14 @@ private fun setParentState(
221223

222224
```
223225

224-
## Making checkboxes accessible
226+
### Making checkbox accessible
225227

226228
Checkboxes support content labeling for accessibility and are readable by most
227229
screen readers, such as TalkBack. Text rendered in checkboxes is automatically
228230
provided to accessibility services. Additional content labels are usually
229231
unnecessary.
230232

231-
## Selecting a checkbox
233+
### Selecting checkbox
232234

233235
In the layout:
234236

@@ -261,7 +263,7 @@ checkbox.addOnCheckedStateChangedListener { checkBox, state ->
261263
}
262264
```
263265

264-
## Setting the error state on checkbox
266+
### Setting error state on checkbox
265267

266268
In the layout:
267269

@@ -287,7 +289,10 @@ checkbox.errorAccessibilityLabel = "Error: custom error announcement."
287289

288290
```
289291

290-
## Making a checkbox indeterminate
292+
### Making checkbox indeterminate
293+
294+
![Checkbox states - unselected, selected(hover), and indeterminate checkboxes](assets/checkbox/checkbox_checked_unchecked_.png)
295+
Unselected, selected (hover), and indeterminate checkboxes
291296

292297
In the layout:
293298

@@ -310,16 +315,16 @@ checkbox.addOnCheckedStateChangedListener { checkBox, state ->
310315
}
311316
```
312317

313-
## Customizing checkboxes
318+
## Customizing checkbox
314319

315-
### Theming checkboxes
320+
### Theming checkbox
316321

317322
Checkboxes support the customization of color and typography.
318323

319324
**Note:** Checkboxes do not support shape theming and are only rounded square
320325
checkboxes.
321326

322-
#### Checkboxes theming example
327+
#### Checkbox theming example
323328

324329
API and source code:
325330

31 KB
Loading
-472 KB
Loading

0 commit comments

Comments
 (0)