Compose Component

Button

Button social preview

ButtonWithImageSample

@Sampled
@Composable
fun ButtonWithImageSample(enabled: Boolean = true) {
    Button(
        onClick = { /* Do something */ },
        containerPainter =
            ButtonDefaults.containerPainter(
                image = painterResource(id = R.drawable.backgroundimage)
            ),
        enabled = enabled,
        label = { Text("Button") },
        secondaryLabel = { Text("Secondary label") },
        icon = {
            Icon(
                painter = painterResource(R.drawable.ic_favorite_rounded),
                contentDescription = "Favorite icon",
            )
        },
        modifier = Modifier.fillMaxWidth(),
    )
}

ButtonSample

@Sampled
@Composable
fun ButtonSample() {
    Button(
        onClick = { /* Do something */ },
        label = { Text("Button") },
        secondaryLabel = { Text("Secondary label") },
        icon = {
            Icon(
                painter = painterResource(R.drawable.ic_favorite_rounded),
                contentDescription = "Favorite icon",
                modifier = Modifier.size(ButtonDefaults.IconSize),
            )
        },
        modifier = Modifier.fillMaxWidth(),
    )
}

ButtonLargeIconSample

@Sampled
@Composable
fun ButtonLargeIconSample(enabled: Boolean = true) {
    // When customising the icon size, it is recommended to also specify
    // the associated content padding
    Button(
        onClick = { /* Do something */ },
        enabled = enabled,
        label = { Text("Button") },
        secondaryLabel = { Text("Secondary label") },
        icon = {
            Icon(
                painter = painterResource(R.drawable.ic_favorite_rounded),
                contentDescription = "Favorite icon",
                modifier = Modifier.size(ButtonDefaults.LargeIconSize),
            )
        },
        contentPadding = ButtonDefaults.ButtonWithLargeIconContentPadding,
        modifier = Modifier.fillMaxWidth(),
    )
}

ButtonExtraLargeIconSample

@Sampled
@Composable
fun ButtonExtraLargeIconSample(enabled: Boolean = true) {
    // When customising the icon size, it is recommended to also specify
    // the associated content padding
    Button(
        onClick = { /* Do something */ },
        enabled = enabled,
        label = { Text("Button") },
        secondaryLabel = { Text("Secondary label") },
        icon = {
            Icon(
                painter = painterResource(R.drawable.ic_favorite_rounded),
                contentDescription = "Favorite icon",
                modifier = Modifier.size(ButtonDefaults.ExtraLargeIconSize),
            )
        },
        contentPadding = ButtonDefaults.ButtonWithExtraLargeIconContentPadding,
        modifier = Modifier.fillMaxWidth(),
    )
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: