androidx.compose.material3

Button

Composable function

A button runs an action when clicked. Put a Text inside, and optionally an Icon.

A basic button
A basic button
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.

The five button types, from most to least emphasis
The five button types, from most to least emphasis
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

Called when the button is clicked.

modifier: ModifierOptional

Default: 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.

Expressive sizesExpressive theme
Expressive sizes
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

Default: true

Set to false to make the button gray and not clickable.

A disabled button
A disabled button
Button(onClick = {}, enabled = false) {
    Text("Save")
}

shape: ShapeOptional

Default: 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.

Rounded corners with a fixed size
Rounded corners with a fixed size
Button(onClick = {}, shape = RoundedCornerShape(8.dp)) {
    Text("8 dp corners")
}

colors: ButtonColorsOptional

Default: 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.

Tertiary colors
Tertiary colors
Button(
    onClick = {},
    colors = ButtonDefaults.buttonColors(
        containerColor = MaterialTheme.colorScheme.tertiary,
        contentColor = MaterialTheme.colorScheme.onTertiary,
    ),
) {
    Text("Continue")
}
A destructive action
A destructive action
Button(
    onClick = {},
    colors = ButtonDefaults.buttonColors(
        containerColor = MaterialTheme.colorScheme.error,
        contentColor = MaterialTheme.colorScheme.onError,
    ),
) {
    Text("Delete")
}

elevation: ButtonElevation?Optional

Default: ButtonDefaults.buttonElevation()

Sets the shadow height. Pass null for no shadow. Make one with ButtonDefaults.buttonElevation.

More shadow
More shadow
Button(
    onClick = {},
    elevation = ButtonDefaults.buttonElevation(defaultElevation = 6.dp),
) {
    Text("Raised")
}

border: BorderStroke?Optional

Default: null

Draws an outline. null means no outline. OutlinedButton has one by default.

A thicker outline
A thicker outline
OutlinedButton(
    onClick = {},
    border = BorderStroke(2.dp, MaterialTheme.colorScheme.primary),
) {
    Text("Follow")
}

contentPadding: PaddingValuesOptional

Default: 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

Default: 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

What 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.

Icon and label
Icon and label
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

Sets two shapes: one at rest and one while pressed. The button animates between them. Make one with ButtonDefaults.shapes. See the Shapes guide.

Shape that changes when pressedExpressive theme
Shape that changes when pressed
Button(onClick = {}, shapes = ButtonDefaults.shapes()) {
    Text("Press me")
}

Same as above: onClick, modifier, enabled, colors, elevation, border, contentPadding, interactionSource, content.

Button types

See also