State of Compose 2023 results are in! Click here to learn more

← Back to Material Compose

BadgeBox

Component
in
Material
. Since 1.0.0

Overview

Code Examples

A BadgeBox is used to decorate content with a badge that can contain dynamic information, such as the presence of a new notification or a number of pending requests. Badges can be icon only or contain short text.

A common use case is to display a badge in the upper right corner of bottom navigation items. For more information, see Bottom Navigation(https://material.io/components/bottom-navigation#behavior)

A simple icon with badge example looks like:

Overloads

BadgeBox

@ExperimentalMaterialApi
@Composable
fun BadgeBox(
    modifier: Modifier = Modifier,
    backgroundColor: Color = MaterialTheme.colors.error,
    contentColor: Color = contentColorFor(backgroundColor),
    badgeContent: @Composable (RowScope.() -> Unit)? = null,
    content: @Composable BoxScope.() -> Unit,
)

Parameters

NameDescription
modifieroptional Modifier for this item
backgroundColorthe background color for the badge
contentColorthe color of label text rendered in the badge
badgeContentoptional content to be rendered inside the badge
contentthe anchor to which this badge will be positione