Computer scienceMobileJetpack ComposeComposablesMaterial

Checkbox, Radio Button, and Switch

Three states in action

Report a typo

Complete the code below to create a TriStateCheckbox with the following features:

  • It should initially be in the Indeterminate state.

  • The checkmark color should be white.

  • The background color when checked should be blue.

Fill in the gaps with the relevant elements
@Composable
fun TriStateCheckboxExample() {
    var state by remember { mutableStateOf(ToggleableState.) }

    TriStateCheckbox(
        state = state,
         = {
            state = when (state) {
                ToggleableState.On -> ToggleableState.Off
                ToggleableState.Off -> ToggleableState.Indeterminate
                ToggleableState.Indeterminate -> ToggleableState.On
            }
        },
        colors = .colors(
             = Color.White,
             = Color.Blue 
        )
    )
}
OncheckmarkColorCheckboxDefaultsonClickcheckedColoronCheckedIndeterminateuncheckedColorOffTriStateCheckboxDefaults

Create a free account to access the full topic