androidx.compose.material3
Button
Composable function
A button runs an action when clicked. Put a Text inside, and optionally an Icon.

Button(onClick = { /* do something */ }) {
Text("Save")
}
There are five button types. Use the filled Button for the main action on a screen. Use the others for less important actions. See Button types for how they differ.

Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Button(onClick = {}) { Text("Filled") }
FilledTonalButton(onClick = {}) { Text("Tonal") }
ElevatedButton(onClick = {}) { Text("Elevated") }
OutlinedButton(onClick = {}) { Text("Outlined") }
TextButton(onClick = {}) { Text("Text") }
}
Basic
Takes one shape.
@Composable
fun Button(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape = ButtonDefaults.shape,
colors: ButtonColors = ButtonDefaults.buttonColors(),
elevation: ButtonElevation? = ButtonDefaults.buttonElevation(),
border: BorderStroke? = null,
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
interactionSource: MutableInteractionSource? = null,
content: @Composable RowScope.() -> Unit,
)
onClick: () -> UnitRequired
onClick: () -> UnitRequiredCalled when the button is clicked.
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position of the button. See the Modifier guide.
Expressive has five button heights, from ButtonDefaults.ExtraSmallContainerHeight to ButtonDefaults.ExtraLargeContainerHeight. Set the height with Modifier.heightIn(), then use the …For(height) helpers in ButtonDefaults so padding, text and shape match.

Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
SizedButton("Extra small", ButtonDefaults.ExtraSmallContainerHeight)
SizedButton("Small", ButtonDefaults.MinHeight)
SizedButton("Medium", ButtonDefaults.MediumContainerHeight)
SizedButton("Large", ButtonDefaults.LargeContainerHeight)
}
/** One button sized for [height]. Each *For(height) helper picks matching values. */
@Composable
fun SizedButton(label: String, height: Dp) {
Button(
onClick = {},
modifier = Modifier.heightIn(height),
shapes = ButtonDefaults.shapesFor(height),
contentPadding = ButtonDefaults.contentPaddingFor(height),
) {
Text(label, style = ButtonDefaults.textStyleFor(height))
}
}
enabled: BooleanOptional
enabled: BooleanOptionalshape: ShapeOptional
shape: ShapeOptionalDefault: ButtonDefaults.shape
Sets the outline of the button. Default: fully rounded.
Use ButtonDefaults.squareShape for the square style, or any other Shape. The Shapes guide lists the options.

Button(onClick = {}, shape = RoundedCornerShape(8.dp)) {
Text("8 dp corners")
}
colors: ButtonColorsOptional
colors: ButtonColorsOptionalDefault: ButtonDefaults.buttonColors()
Sets the background and text colors, for both enabled and disabled.
Make one with ButtonDefaults.buttonColors. Each button type has its own function, for example ButtonDefaults.outlinedButtonColors.

Button(
onClick = {},
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.tertiary,
contentColor = MaterialTheme.colorScheme.onTertiary,
),
) {
Text("Continue")
}

Button(
onClick = {},
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.error,
contentColor = MaterialTheme.colorScheme.onError,
),
) {
Text("Delete")
}
elevation: ButtonElevation?Optional
elevation: ButtonElevation?OptionalDefault: ButtonDefaults.buttonElevation()
Sets the shadow height. Pass null for no shadow.
Make one with ButtonDefaults.buttonElevation.

Button(
onClick = {},
elevation = ButtonDefaults.buttonElevation(defaultElevation = 6.dp),
) {
Text("Raised")
}
border: BorderStroke?Optional
border: BorderStroke?OptionalDefault: null
Draws an outline. null means no outline. OutlinedButton has one by default.

OutlinedButton(
onClick = {},
border = BorderStroke(2.dp, MaterialTheme.colorScheme.primary),
) {
Text("Follow")
}
contentPadding: PaddingValuesOptional
contentPadding: PaddingValuesOptionalDefault: ButtonDefaults.ContentPadding
Space between the edge of the button and the content.
Use ButtonDefaults.ButtonWithIconContentPadding when the button has a leading icon.
interactionSource: MutableInteractionSource?Optional
interactionSource: MutableInteractionSource?OptionalDefault: null
Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.
content: @Composable RowScope.() -> UnitRequired
content: @Composable RowScope.() -> UnitRequiredWhat the button shows. Usually a Text, sometimes an Icon and a Text.
The content is placed in a Row, so items sit side by side.

Button(
onClick = {},
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
) {
Icon(Icons.Filled.Add, contentDescription = null, modifier = Modifier.size(ButtonDefaults.IconSize))
Spacer(Modifier.width(ButtonDefaults.IconSpacing))
Text("Add item")
}
ExpressiveSince 1.10
Takes shapes: one shape at rest and one while pressed. The button morphs between them.
@Composable
fun Button(
onClick: () -> Unit,
shapes: ButtonShapes,
modifier: Modifier = Modifier,
enabled: Boolean = true,
colors: ButtonColors = ButtonDefaults.buttonColors(),
elevation: ButtonElevation? = ButtonDefaults.buttonElevation(),
border: BorderStroke? = null,
contentPadding: PaddingValues = ButtonDefaults.contentPaddingFor(ButtonDefaults.MinHeight),
interactionSource: MutableInteractionSource? = null,
content: @Composable RowScope.() -> Unit,
)
shapes: ButtonShapesRequired
shapes: ButtonShapesRequiredSets two shapes: one at rest and one while pressed. The button animates between them.
Make one with ButtonDefaults.shapes. See the Shapes guide.

Button(onClick = {}, shapes = ButtonDefaults.shapes()) {
Text("Press me")
}
Same as above: onClick, modifier, enabled, colors, elevation, border, contentPadding, interactionSource, content.
Button types
See also
ButtonDefaults: default values and helper functions forButton.
