# Button

## 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/Button.composable#Button(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.wear.compose.material.ButtonBorder,kotlin.Function1)( onClick: () -> 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/ButtonColors, interactionSource: https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource?, shape: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shape, border: https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonBorder, 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/Button.composable#Button(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.wear.compose.material.ButtonBorder,kotlin.Function1)` that offers a single slot to take any content (text, icon or image). |

## Functions

### Button

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/Button.kt+function:Button) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.1.0)

```
@Composable
fun Button(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: ButtonColors = ButtonDefaults.primaryButtonColors(),
    interactionSource: MutableInteractionSource? = null,
    shape: Shape = CircleShape,
    border: ButtonBorder = ButtonDefaults.buttonBorder(),
    content: @Composable BoxScope.() -> Unit
): Unit
```

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

The recommended `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Button.composable#Button(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.wear.compose.material.ButtonBorder,kotlin.Function1)` sizes can be obtained from `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults` - see `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults#DefaultButtonSize()`, `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults#LargeButtonSize()`, `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults#SmallButtonSize()`. Icon content should be of size `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults#DefaultIconSize()`, `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults#LargeIconSize()` or `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults#SmallIconSize()` respectively.

The recommended set of `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonColors` styles can be obtained from `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults`, e.g. `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults#primaryButtonColors(androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color)` to get a color scheme for a primary `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Button.composable#Button(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.wear.compose.material.ButtonBorder,kotlin.Function1)` which by default will have a solid background of `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Colors#primary()` and content color of `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Colors#onPrimary()`.

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

Example of a `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Button.composable#Button(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.wear.compose.material.ButtonBorder,kotlin.Function1)` displaying an icon:

```kotlin
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.wear.compose.material.Button
import androidx.wear.compose.material.ButtonDefaults
import androidx.wear.compose.material.Icon

Button(onClick = { /* Do something */ }, enabled = true) {
    Icon(
        painter = painterResource(id = R.drawable.ic_airplanemode_active_24px),
        contentDescription = "airplane",
        modifier =
            Modifier.size(ButtonDefaults.DefaultIconSize)
                .wrapContentSize(align = Alignment.Center),
    )
}
```

Example of a large `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Button.composable#Button(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.wear.compose.material.ButtonBorder,kotlin.Function1)` displaying an icon:

```kotlin
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.wear.compose.material.Button
import androidx.wear.compose.material.ButtonDefaults
import androidx.wear.compose.material.Icon

Button(
    onClick = { /* Do something */ },
    enabled = true,
    modifier = Modifier.size(ButtonDefaults.LargeButtonSize),
) {
    Icon(
        painter = painterResource(id = R.drawable.ic_airplanemode_active_24px),
        contentDescription = "airplane",
        modifier =
            Modifier.size(ButtonDefaults.LargeIconSize)
                .wrapContentSize(align = Alignment.Center),
    )
}
```

Example of a `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Button.composable#Button(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.wear.compose.material.ButtonBorder,kotlin.Function1)` with text content and size modified to LargeButtonSize:

```kotlin
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.wear.compose.material.Button
import androidx.wear.compose.material.ButtonDefaults
import androidx.wear.compose.material.Text

Button(
    onClick = { /* Do something */ },
    enabled = true,
    modifier = Modifier.size(ButtonDefaults.LargeButtonSize),
) {
    Text("Big")
}
```

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

| Parameters |
|---|---|
| `onClick: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | Will be called when the user clicks the button. |
| `modifier: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier = Modifier` | Modifier to be applied to the button. |
| `enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = true` | Controls the enabled state of the button. When `false`, this button will not be clickable. |
| `colors: https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonColors = ButtonDefaults.primaryButtonColors()` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonColors` that will be used to resolve the background and content color for this button in different states. See `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults#buttonColors(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 button. You can use this to change the button's appearance or preview the 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 button's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material Theme. |
| `border: https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonBorder = ButtonDefaults.buttonBorder()` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonBorder` that will be used to resolve the button border in different states. See `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ButtonDefaults#buttonBorder(androidx.compose.foundation.BorderStroke,androidx.compose.foundation.BorderStroke)`. |
| `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 content displayed on the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/Button.composable#Button(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.material.ButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.wear.compose.material.ButtonBorder,kotlin.Function1)` such as text, icon or image. |