Files
AndroidJetpack/Jetpack-Compose-Playground/docs/material/button.md
T
2026-07-15 16:57:36 +08:00

1.6 KiB

Button

A Button has a onClick-Function. You can add a Text-Composable or any other Composables as child elements of the Button.

@Composable
fun ButtonExample() {
    Button(onClick = { /* Do something! */ }, colors = ButtonDefaults.textButtonColors(
        backgroundColor = Color.Red
    )) {
        Text("Button")
    }
}

OutlinedButton

@Composable
fun OutlinedButtonExample() {
    OutlinedButton(onClick = { /* Do something! */ }) {
       Text("I'm an Outlined Button")
   }
}

TextButton

@Composable
fun TextButtonExample() {
    TextButton(onClick = { /* Do something! */ }) {
        Text("I'm a Text Button")
    }
}

### See also: * [Official Docs](https://developer.android.com/reference/kotlin/androidx/compose/material/package-summary#Button(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.material.ButtonElevation,androidx.compose.ui.graphics.Shape,androidx.compose.foundation.BorderStroke,androidx.compose.material.ButtonColors,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1)) * [Full Example Code]({{ site.samplefolder }}/material/button/ButtonExample.kt)