Short answer: in Jetpack Compose with Material 3, a bottom navigation bar is a NavigationBar with one NavigationBarItem per destination, placed in the bottomBar slot of a Scaffold and connected to a NavHost from Navigation Compose. The key detail is to navigate with launchSingleTop, saveState and restoreState, so tabs keep their state and do not pile up on the back stack.
Step 1: Add the dependency
dependencies {
implementation("androidx.navigation:navigation-compose:NAV_VERSION")
}
Use the latest version from the official Navigation documentation.
Step 2: Define your destinations
sealed class Screen(val route: String, val label: String, val icon: ImageVector) {
data object Home : Screen("home", "Home", Icons.Filled.Home)
data object Search : Screen("search", "Search", Icons.Filled.Search)
data object Profile : Screen("profile", "Profile", Icons.Filled.Person)
}
val bottomItems = listOf(Screen.Home, Screen.Search, Screen.Profile)
data object needs Kotlin 1.9 or newer; use object on older versions. Keeping the route, label and icon together in one class avoids mistakes when you add a tab.
Step 3: Build the screen with Scaffold, NavigationBar and NavHost
@Composable
fun MainScreen() {
val navController = rememberNavController()
val backStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = backStackEntry?.destination
Scaffold(
bottomBar = {
NavigationBar {
bottomItems.forEach { screen ->
NavigationBarItem(
selected = currentDestination?.hierarchy
?.any { it.route == screen.route } == true,
onClick = {
navController.navigate(screen.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
},
icon = { Icon(screen.icon, contentDescription = screen.label) },
label = { Text(screen.label) }
)
}
}
}
) { innerPadding ->
NavHost(
navController = navController,
startDestination = Screen.Home.route,
modifier = Modifier.padding(innerPadding)
) {
composable(Screen.Home.route) { HomeScreen() }
composable(Screen.Search.route) { SearchScreen() }
composable(Screen.Profile.route) { ProfileScreen() }
}
}
}
@Composable fun HomeScreen() { Text("Home") }
@Composable fun SearchScreen() { Text("Search") }
@Composable fun ProfileScreen() { Text("Profile") }
Required imports include androidx.navigation.compose.currentBackStackEntryAsState, androidx.navigation.NavDestination.Companion.hierarchy and androidx.navigation.NavGraph.Companion.findStartDestination. Always apply innerPadding to the NavHost so content is not hidden behind the bar.
Why the navigation options matter
popUpTo(startDestination)withsaveState = truekeeps the back stack small and saves each tab’s state.launchSingleTop = trueprevents opening the same tab twice when it is tapped again.restoreState = truerestores a tab’s scroll position and state when you return to it.
Add a badge
icon = {
BadgedBox(badge = { Badge { Text("3") } }) {
Icon(Screen.Profile.icon, contentDescription = "Profile")
}
}
Hide the bar on some screens
Show the bar only on top-level screens by checking the current route:
val showBottomBar = bottomItems.any { it.route == currentDestination?.route }
Scaffold(
bottomBar = { if (showBottomBar) { NavigationBar { /* items */ } } }
) { /* NavHost */ }
Detail screens that you open from a tab, such as a product page, then use the full screen. See our Compose navigation guide for arguments and ViewModels.
Common mistakes
- Calling
navigate(route)without options. Each tap adds a new screen to the back stack, and the back button needs many presses. - Forgetting the inner padding. The bottom of your content hides behind the bar.
- Using string routes in many places. Define them once, as above.
- Creating the NavController inside each tab. Create one at the top level.
FAQ
How do I add a bottom navigation bar in Jetpack Compose?
Use Material 3 NavigationBar in a Scaffold’s bottomBar, with a NavHost for the content.
What replaced BottomNavigation in Material 3?
NavigationBar and NavigationBarItem replace the Material 2 BottomNavigation.
How do I keep each tab’s state?
Use saveState = true in popUpTo and restoreState = true in the navigate options.
How many tabs should a bottom bar have?
Material guidelines suggest three to five.
See also: navigation drawer in Compose and more Jetpack Compose tutorials.