androidx.compose.material3

NavigationBar

Composable function

A navigation bar switches between the main destinations of an app. Use it on phones, with three to five items. On wider screens, use a NavigationRail instead.

Put it in the bottomBar slot of a Scaffold. Inside, add one NavigationBarItem per destination.

The bar does not know which item is selected. You keep the selected index in a variable.

Three destinations
Three destinations
var selected by remember { mutableIntStateOf(0) }
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 = null) },
            label = { Text(label) },
        )
    }
}

Parameters

@Composable
fun NavigationBar(
    modifier: Modifier = Modifier,
    containerColor: Color = NavigationBarDefaults.containerColor,
    contentColor: Color = MaterialTheme.colorScheme.contentColorFor(containerColor),
    tonalElevation: Dp = NavigationBarDefaults.Elevation,
    windowInsets: WindowInsets = NavigationBarDefaults.windowInsets,
    content: @Composable RowScope.() -> Unit,
)

modifier: ModifierOptional

Default: Modifier

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

containerColor: ColorOptional

Default: NavigationBarDefaults.containerColor

The background color of the bar.

contentColor: ColorOptional

Default: MaterialTheme.colorScheme.contentColorFor(containerColor)

The default color for content inside the bar.

tonalElevation: DpOptional

Default: NavigationBarDefaults.Elevation

Tints the background a little toward the primary color, to set the bar apart from the page.

windowInsets: WindowInsetsOptional

Default: NavigationBarDefaults.windowInsets

Space kept free for system bars, like the gesture bar on phones. The default is usually right.

content: @Composable RowScope.() -> UnitRequired

The items. Add one NavigationBarItem for each destination. They share the width equally.

Parts

See also