# ToggleButton

## Functions summary

|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButton.composable#ToggleButton(kotlin.Boolean,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ToggleButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.compose.ui.semantics.Role,kotlin.Function1)( checked: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, onCheckedChange: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html, modifier: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier, enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, colors: https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButtonColors, interactionSource: https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource?, shape: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shape, role: https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/Role, content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/BoxScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Wear Material `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButton.composable#ToggleButton(kotlin.Boolean,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ToggleButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.compose.ui.semantics.Role,kotlin.Function1)` that offers a single slot to take any content (text, icon or image). |

## Functions

### ToggleButton

Artifact: [androidx.wear.compose:compose-material](https://developer.android.com/jetpack/androidx/releases/wear-compose) [View Source](https://cs.android.com/search?q=file:androidx/wear/compose/material/ToggleButton.kt+function:ToggleButton)

```
@Composable
fun ToggleButton(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: ToggleButtonColors = ToggleButtonDefaults.toggleButtonColors(),
    interactionSource: MutableInteractionSource? = null,
    shape: Shape = CircleShape,
    role: Role = ToggleButtonDefaults.DefaultRole,
    content: @Composable BoxScope.() -> Unit
): Unit
```

Wear Material `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButton.composable#ToggleButton(kotlin.Boolean,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ToggleButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.compose.ui.semantics.Role,kotlin.Function1)` that offers a single slot to take any content (text, icon or image).

The `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButton.composable#ToggleButton(kotlin.Boolean,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ToggleButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.compose.ui.semantics.Role,kotlin.Function1)` defaults to size `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButtonDefaults#DefaultToggleButtonSize()` or `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButtonDefaults#SmallToggleButtonSize()`. Icon content should be of size `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButtonDefaults#DefaultIconSize()` or `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButtonDefaults#SmallIconSize()` respectively.

The recommended set of checked and unchecked `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButtonColors` can be obtained from `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButtonDefaults#toggleButtonColors(androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color)`, which defaults to checked colors being a solid background of `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Colors#primary()` with content color of `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Colors#onPrimary()` and unchecked colors being a solid background of `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Colors#surface()` with content color of `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Colors#onSurface()`.

`https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButton.composable#ToggleButton(kotlin.Boolean,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ToggleButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.compose.ui.semantics.Role,kotlin.Function1)`s can be enabled or disabled. A disabled toggle button will not respond to click events.

Example of a `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButton.composable#ToggleButton(kotlin.Boolean,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ToggleButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.compose.ui.semantics.Role,kotlin.Function1)` with an icon:

```kotlin
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.ToggleButton
import androidx.wear.compose.material.ToggleButtonDefaults

var checked by remember { mutableStateOf(true) }
ToggleButton(checked = checked, onCheckedChange = { checked = it }, enabled = true) {
    Icon(
        painter = painterResource(id = R.drawable.ic_airplanemode_active_24px),
        contentDescription = "airplane",
        modifier =
            Modifier.size(ToggleButtonDefaults.DefaultIconSize)
                .wrapContentSize(align = Alignment.Center),
    )
}
```

For more information, see the [Buttons](https://developer.android.com/training/wearables/components/buttons#toggle-button) guide.

| Parameters |
|---|---|
| `checked: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Boolean flag indicating whether this toggle button is currently checked. |
| `onCheckedChange: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | Callback to be invoked when this toggle button is clicked. |
| `modifier: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier = Modifier` | Modifier to be applied to the toggle button. |
| `enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = true` | Controls the enabled state of the toggle button. When `false`, this toggle button will not be clickable. |
| `colors: https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButtonColors = ToggleButtonDefaults.toggleButtonColors()` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButtonColors` that will be used to resolve the background and content color for this toggle button. See `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ToggleButtonDefaults#toggleButtonColors(androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color)`. |
| `interactionSource: https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource? = null` | an optional hoisted `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` for observing and emitting `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/Interaction`s for this toggle button. You can use this to change the toggle button's appearance or preview the toggle button in different states. Note that if `null` is provided, interactions will still happen internally. |
| `shape: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shape = CircleShape` | Defines the shape for this toggle button. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material Theme. |
| `role: https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/Role = ToggleButtonDefaults.DefaultRole` | Role semantics that accessibility services can use to provide more context to users. |
| `content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/BoxScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The icon, image or text to be drawn inside the toggle button. |