[ Web Proxy ]
URL:
Viewing: http://developer.android.com/develop/ui/compose/components/checkbox [Back]  [Original]

Checkbox  |  Jetpack Compose  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]

Checkbox Stay organized with collections Save and categorize content based on your preferences.

Checkboxes let users select one or more items from a list. You might use a checkbox to let the user do the following:

Note: Use checkboxes instead of switches or radio buttons if the user can select multiple options in a list.

Anatomy

A checkbox consists of the following elements:

States

A checkbox can be in one of three states:

The following image demonstrates the three states of a checkbox.

An example of a checkbox component in each of its three states: unselected, selected, and indeterminate. [An example of a checkbox component in each of its three states: unselected, selected, and indeterminate.] Figure 1. The three states of a checkbox. Unselected, indeterminate, and selected.

Implementation

You can use the Checkbox composable to create a checkbox in your app. There are just a few key parameters to keep in mind:

The following snippet demonstrates how to use the Checkbox composable:

@Composable
fun CheckboxMinimalExample() {
    var checked by remember { mutableStateOf(true) }

    Row(
        verticalAlignment = Alignment.CenterVertically,
    ) {
        Text(
            "Minimal checkbox"
        )
        Checkbox(
            checked = checked,
            onCheckedChange = { checked = it }
        )
    }

    Text(
        if (checked) "Checkbox is checked" else "Checkbox is unchecked"
    )
}

Explanation

This code creates a checkbox that is initially unchecked. When the user clicks on the checkbox, the onCheckedChange lambda updates the checked state.

Result

This example produces the following component when unchecked:

An unchecked checkbox with a label. The text beneath it reads 'Checkbox is unchecked' [An unchecked checkbox with a label. The text beneath it reads 'Checkbox is unchecked'] Figure 2. Unchecked checkbox

And this is how the same checkbox appears when checked:

A checked checkbox with a label. The text beneath it reads 'Checkbox is checked' [A checked checkbox with a label. The text beneath it reads 'Checkbox is checked'] Figure 3. Checked checkbox

Advanced example

The following is a more complex example of how you can implement checkboxes in your app. In this snippet, there is a parent checkbox and a series of child checkboxes. When the user taps the parent checkbox, the app checks all child checkboxes.

@Composable
fun CheckboxParentExample() {
    // Initialize states for the child checkboxes
    val childCheckedStates = remember { mutableStateListOf(false, false, false) }

    // Compute the parent state based on children's states
    val parentState = when {
        childCheckedStates.all { it } -> ToggleableState.On
        childCheckedStates.none { it } -> ToggleableState.Off
        else -> ToggleableState.Indeterminate
    }

    Column {
        // Parent TriStateCheckbox
        Row(
            verticalAlignment = Alignment.CenterVertically,
        ) {
            Text("Select all")
            TriStateCheckbox(
                state = parentState,
                onClick = {
                    // Determine new state based on current state
                    val newState = parentState != ToggleableState.On
                    childCheckedStates.forEachIndexed { index, _ ->
                        childCheckedStates[index] = newState
                    }
                }
            )
        }

        // Child Checkboxes
        childCheckedStates.forEachIndexed { index, checked ->
            Row(
                verticalAlignment = Alignment.CenterVertically,
            ) {
                Text("Option ${index + 1}")
                Checkbox(
                    checked = checked,
                    onCheckedChange = { isChecked ->
                        // Update the individual child state
                        childCheckedStates[index] = isChecked
                    }
                )
            }
        }
    }

    if (childCheckedStates.all { it }) {
        Text("All options selected")
    }
}

Explanation

The following are several points you should note from this example:

Note: If you want to have a checkbox with an indeterminate state, you must use TriStateCheckbox. This is because it has a state parameter of type ToggleableState, whereas Checkbox does not.

Result

This example produces the following component when all checkboxes are unchecked.

A series of unchecked labeled checkboxes with a label. [A series of unchecked labeled checkboxes with a label.] Figure 4. Unchecked checkboxes

Likewise, this is how the component appears when all options are checked, as when the user taps select all:

A series of checked labeled checkboxes with a label. The first is marked 'select all'. There is a text component beneath them that reads 'all options selected.' [A series of checked labeled checkboxes with a label. The first is marked 'select all'. There is a text component beneath them that reads 'all options selected.'] Figure 5. Checked checkboxes

When only one option is checked the parent checkbox displays the indeterminate state:

A series of unchecked labeled checkboxes with a label. All but one is unchecked. The checkbox labeled 'select all' is indeterminate, displaying a dash. [A series of unchecked labeled checkboxes with a label. All but one is unchecked. The checkbox labeled 'select all' is indeterminate, displaying a dash.] Figure 6. Indeterminate checkbox

Additional resources

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-08-14 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-14 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page