ToggleControlScope


class ToggleControlScope


ToggleControlScope provides enabled and checked properties. This allows toggle controls to omit enabled/checked parameters as they given by the scope.

Summary

Public constructors

ToggleControlScope(isEnabled: Boolean, isChecked: Boolean)

Public properties

Boolean

Indicates whether the control is currently checked.

Boolean

Controls the enabled state of the toggle control.

Extension functions

Unit

Checkbox provides an animated checkbox for use as a toggle control in ToggleButton or SplitToggleButton.

Unit

Switch provides an animated switch for use as a toggle control in ToggleButton or SplitToggleButton.

Public constructors

ToggleControlScope

Added in 1.0.0-alpha21
ToggleControlScope(isEnabled: Boolean, isChecked: Boolean)
Parameters
isEnabled: Boolean

Controls the enabled state of the toggle control. When false, the control is displayed with disabled colors.

isChecked: Boolean

Indicates whether the control is currently checked.

Public properties

isChecked

Added in 1.0.0-alpha21
val isCheckedBoolean

Indicates whether the control is currently checked.

isEnabled

Added in 1.0.0-alpha21
val isEnabledBoolean

Controls the enabled state of the toggle control. When false, the control is displayed with disabled colors.

Extension functions

@Composable
fun ToggleControlScope.Checkbox(
    modifier: Modifier = Modifier,
    colors: CheckboxColors = CheckboxDefaults.colors()
): Unit

Checkbox provides an animated checkbox for use as a toggle control in ToggleButton or SplitToggleButton.

Checkbox sample:

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.text.style.TextOverflow
import androidx.wear.compose.material3.Checkbox
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.ToggleButton

var checked by remember { mutableStateOf(true) }
ToggleButton(
    label = {
        Text("Checkbox", maxLines = 3, overflow = TextOverflow.Ellipsis)
    },
    secondaryLabel = {
        Text("With secondary label", maxLines = 2, overflow = TextOverflow.Ellipsis)
    },
    checked = checked,
    toggleControl = { Checkbox() },
    onCheckedChange = { checked = it },
    icon = {
        Icon(
            Icons.Filled.Favorite,
            contentDescription = "Favorite icon"
        )
    },
    enabled = true,
)
Parameters
modifier: Modifier = Modifier

Modifier to be applied to the checkbox. This can be used to provide a content description for accessibility.

colors: CheckboxColors = CheckboxDefaults.colors()

CheckboxColors from which the box and checkmark colors will be obtained.

@Composable
fun ToggleControlScope.Switch(
    modifier: Modifier = Modifier,
    colors: SwitchColors = SwitchDefaults.colors()
): Unit

Switch provides an animated switch for use as a toggle control in ToggleButton or SplitToggleButton.

Switch samples:

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.text.style.TextOverflow
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.Switch
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.ToggleButton

var checked by remember { mutableStateOf(true) }
ToggleButton(
    label = {
        Text("Switch", maxLines = 3, overflow = TextOverflow.Ellipsis)
    },
    secondaryLabel = {
        Text("With secondary label", maxLines = 2, overflow = TextOverflow.Ellipsis)
    },
    checked = checked,
    toggleControl = { Switch() },
    onCheckedChange = { checked = it },
    icon = {
        Icon(
            Icons.Filled.Favorite,
            contentDescription = "Favorite icon"
        )
    },
    enabled = true,
)
Parameters
modifier: Modifier = Modifier

Modifier to be applied to the switch. This can be used to provide a content description for accessibility.

colors: SwitchColors = SwitchDefaults.colors()

SwitchColors from which the colors of the thumb and track will be obtained.