TextButton

Composable Component

Wear Material TextButton is a circular, text-only button with transparent background and no border. It offers a single slot for text.

Android
@Composable
public fun TextButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    onLongClick: (() -> Unit)? = null,
    onLongClickLabel: String? = null,
    enabled: Boolean = true,
    shapes: TextButtonShapes = TextButtonDefaults.shapes(),
    colors: TextButtonColors = TextButtonDefaults.textButtonColors(),
    border: BorderStroke? = null,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable BoxScope.() -> Unit,
)

Parameters

onClick Will be called when the user clicks the button.
modifier Modifier to be applied to the button.
onLongClick Called when this button is long clicked (long-pressed). When this callback is set, onLongClickLabel should be set as well.
onLongClickLabel Semantic / accessibility label for the onLongClick action.
enabled Controls the enabled state of the button. When false, this button will not be clickable.
shapes Defines the shape for this button. Defaults to a static shape based on TextButtonDefaults.shape, but animated versions are available through TextButtonDefaults.animatedShapes.
colors TextButtonColors that will be used to resolve the background and content color for this button in different states.
border Optional BorderStroke that will be used to resolve the text button border in different states. See ButtonDefaults.outlinedButtonBorder.
interactionSource an optional hoisted MutableInteractionSource for observing and emitting Interactions 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.
content The content displayed on the text button, expected to be text or image.

Code Examples

LargeFilledTonalTextButtonSample

@Composable
fun LargeFilledTonalTextButtonSample() {
    TextButton(
        onClick = { /* Do something */ },
        colors = TextButtonDefaults.filledTonalTextButtonColors(),
        modifier = Modifier.size(TextButtonDefaults.LargeButtonSize),
    ) {
        Text(text = "ABC", style = TextButtonDefaults.largeButtonTextStyle)
    }
}

TextButtonSample

@Composable
fun TextButtonSample() {
    TextButton(onClick = { /* Do something */ }) { Text(text = "ABC") }
}

TextButtonWithCornerAnimationSample

@Composable
fun TextButtonWithCornerAnimationSample() {
    TextButton(onClick = { /* Do something */ }, shapes = TextButtonDefaults.animatedShapes()) {
        Text(text = "ABC")
    }
}

TextButtonWithOnLongClickSample

@Composable
fun TextButtonWithOnLongClickSample(onLongClick: () -> Unit) {
    TextButton(
        onClick = { /* Do something for onClick*/ },
        onLongClick = onLongClick,
        onLongClickLabel = "Long click",
    ) {
        Text(text = "ABC")
    }
}