Compose Component

FilledTonalIconToggleButton

Material Design filled tonal icon toggle button Icon buttons help people take supplementary actions with a single tap.

FilledTonalIconToggleButton social preview

FilledTonalIconToggleButtonSample

@Preview
@Sampled
@Composable
fun FilledTonalIconToggleButtonSample() {
    var checked by rememberSaveable { mutableStateOf(false) }
    val description = "Localized description"
    // Icon button should have a tooltip associated with it for a11y.
    TooltipBox(
        positionProvider =
            TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Above),
        tooltip = {
            PlainTooltip(
                modifier =
                    Modifier.semantics {
                        // TODO(b/496338253): Remove this modifier once bug where tooltip text is
                        //  not announced by a11y screen readers is resolved.
                        liveRegion = LiveRegionMode.Assertive
                        paneTitle = description
                    }
            ) {
                Text(description)
            }
        },
        state = rememberTooltipState(),
    ) {
        FilledTonalIconToggleButton(checked = checked, onCheckedChange = { checked = it }) {
            if (checked) {
                Icon(Icons.Filled.Lock, contentDescription = description)
            } else {
                Icon(Icons.Outlined.Lock, contentDescription = description)
            }
        }
    }
}

FilledTonalIconToggleButtonWithAnimatedShapeSample

@Preview
@Sampled
@Composable
fun FilledTonalIconToggleButtonWithAnimatedShapeSample() {
    var checked by rememberSaveable { mutableStateOf(false) }
    val description = "Localized description"
    // Icon button should have a tooltip associated with it for a11y.
    TooltipBox(
        positionProvider =
            TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Above),
        tooltip = {
            PlainTooltip(
                modifier =
                    Modifier.semantics {
                        // TODO(b/496338253): Remove this modifier once bug where tooltip text is
                        //  not announced by a11y screen readers is resolved.
                        liveRegion = LiveRegionMode.Assertive
                        paneTitle = description
                    }
            ) {
                Text(description)
            }
        },
        state = rememberTooltipState(),
    ) {
        FilledTonalIconToggleButton(
            checked = checked,
            onCheckedChange = { checked = it },
            shapes = IconButtonDefaults.toggleableShapes(),
        ) {
            if (checked) {
                Icon(Icons.Filled.Lock, contentDescription = description)
            } else {
                Icon(Icons.Outlined.Lock, contentDescription = description)
            }
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: