androidx.compose.material3

NavigationBarItem

Composable function

A part of NavigationBar. See that page for an overview and examples.

Parameters

@Composable
fun RowScope.NavigationBarItem(
    selected: Boolean,
    onClick: () -> Unit,
    icon: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    label: @Composable (() -> Unit)? = null,
    alwaysShowLabel: Boolean = true,
    colors: NavigationBarItemColors = NavigationBarItemDefaults.colors(),
    interactionSource: MutableInteractionSource? = null,
)

selected: BooleanRequired

Whether this item is the current destination. Usually index == selectedIndex.

onClick: () -> UnitRequired

Called when the item is clicked. Set your selected index and navigate here.

icon: @Composable () -> UnitRequired

The icon of the item. Wrap it in a BadgedBox to show a count.

An item with a badge
An item with a badge
NavigationBar(Modifier.width(360.dp)) {
    NavigationBarItem(selected = true, onClick = {}, icon = { Icon(Icons.Filled.Home, null) }, label = { Text("Home") })
    NavigationBarItem(
        selected = false,
        onClick = {},
        icon = {
            BadgedBox(badge = { Badge { Text("3") } }) { Icon(Icons.Filled.Favorite, null) }
        },
        label = { Text("Favorites") },
    )
}

enabled: BooleanOptional

Default: true

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

label: @Composable (() -> Unit)?Optional

Default: null

The name of the destination. Keep it to one short word.

alwaysShowLabel: BooleanOptional

Default: true

Set to false to show the label only on the selected item.

Labels only on the selected item
Labels only on the selected item
var selected by remember { mutableIntStateOf(1) }
val items = listOf("Home" to Icons.Filled.Home, "Favorites" to Icons.Filled.Favorite, "Settings" to Icons.Filled.Settings)
NavigationBar(Modifier.width(360.dp)) {
    items.forEachIndexed { index, (label, icon) ->
        NavigationBarItem(
            selected = selected == index,
            onClick = { selected = index },
            icon = { Icon(icon, contentDescription = label) },
            label = { Text(label) },
            alwaysShowLabel = false,
        )
    }
}

colors: NavigationBarItemColorsOptional

Default: NavigationBarItemDefaults.colors()

Sets icon, label and indicator colors for selected, unselected and disabled items. Make one with NavigationBarItemDefaults.colors.

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.

Same as in NavigationBar: modifier.

Parts

See also