androidx.compose.material3

BadgedBox

Composable function

A badge shows a count or a dot on an icon, for example unread messages.

Put the icon in a BadgedBox, and the Badge in its badge slot. The box places the badge on the top end corner.

A count and a dot
A count and a dot
Row(horizontalArrangement = Arrangement.spacedBy(32.dp)) {
    BadgedBox(badge = { Badge { Text("8") } }) {
        Icon(Icons.Filled.Email, contentDescription = "8 new messages")
    }
    BadgedBox(badge = { Badge() }) {
        Icon(Icons.Filled.Notifications, contentDescription = "New notifications")
    }
}

A badge without content is a small dot. With a Text inside, it grows to fit. Keep the text short, like "999+".

A badge on a navigation icon
A badge on a navigation icon
Box(Modifier.padding(8.dp)) {
    BadgedBox(badge = { Badge { Text("999+") } }) {
        Icon(Icons.Filled.Email, contentDescription = "Many messages")
    }
}

Parameters

@Composable
fun BadgedBox(
    badge: @Composable BoxScope.() -> Unit,
    modifier: Modifier = Modifier,
    content: @Composable BoxScope.() -> Unit,
)

badge: @Composable BoxScope.() -> UnitRequired

The badge. Usually a Badge.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

content: @Composable BoxScope.() -> UnitRequired

The thing the badge sits on. Usually an Icon.

Parts