androidx.compose.material3

NavigationRail

Composable function

A navigation rail switches between the main destinations of an app, like a NavigationBar, but sits at the side. Use it on tablets and desktops. Put it next to your content in a Row.

Inside, add one NavigationRailItem per destination. You keep the selected index in a variable.

A rail with a FAB in the header
A rail with a FAB in the header
var selected by remember { mutableIntStateOf(0) }
val items = listOf("Home" to Icons.Filled.Home, "Favorites" to Icons.Filled.Favorite, "Settings" to Icons.Filled.Settings)
NavigationRail(
    modifier = Modifier.height(400.dp),
    header = {
        FloatingActionButton(onClick = {}) { Icon(Icons.Filled.Add, "Add") }
    },
) {
    items.forEachIndexed { index, (label, icon) ->
        NavigationRailItem(
            selected = selected == index,
            onClick = { selected = index },
            icon = { Icon(icon, contentDescription = null) },
            label = { Text(label) },
        )
    }
}

Parameters

@Composable
fun NavigationRail(
    modifier: Modifier = Modifier,
    containerColor: Color = NavigationRailDefaults.ContainerColor,
    contentColor: Color = contentColorFor(containerColor),
    header: @Composable (ColumnScope.() -> Unit)? = null,
    windowInsets: WindowInsets = NavigationRailDefaults.windowInsets,
    content: @Composable ColumnScope.() -> Unit,
)

modifier: ModifierOptional

Default: Modifier

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

containerColor: ColorOptional

Default: NavigationRailDefaults.ContainerColor

The background color of the rail.

contentColor: ColorOptional

Default: contentColorFor(containerColor)

The default color for content inside the rail.

header: @Composable (ColumnScope.() -> Unit)?Optional

Default: null

Something above the items, usually a FloatingActionButton or a menu button.

windowInsets: WindowInsetsOptional

Default: NavigationRailDefaults.windowInsets

Space kept free for system bars. The default is usually right.

content: @Composable ColumnScope.() -> UnitRequired

The items. Add one NavigationRailItem for each destination. Items are placed in a Column, top to bottom.

Parts

See also