Navigation in Jetpack Compose

Sep 10 2024 · Kotlin 1.9, Android 14, Android Studio Jellyfish

Lesson 05: Bottom Nav Bar Navigation

Demo

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In this demo, you’ll add bottom-bar navigation to the movie-booking app you’ve been building on in the previous lessons.

bottomBar = {
  NavigationBar {

  }
}
var selectedNavBarIndex by remember { mutableIntStateOf(0) }
Scaffold(...) {
  ...
}
NavigationBar {
  NavigationBarItem(
    selected = selectedNavBarIndex == 0,
    label = { Text(text = "Home") },
    onClick = {
      navController.navigate(WELCOME_SCREEN.route)
    },
    icon = {
      Icon(
        imageVector = if (selectedNavBarIndex == 0) Icons.Filled.Home else Icons.Outlined.Home,
        contentDescription = "Home"
      )
    }
  )

  NavigationBarItem(
    selected = selectedNavBarIndex == 1,
    label = { Text(text = "Book Movie") },
    onClick = {
      navController.navigate(MOVIE_SELECTION_SCREEN.route)
    },
    icon = {
      Icon(
        imageVector = if (selectedNavBarIndex == 1) Icons.Filled.Add else Icons.Outlined.Add,
        contentDescription = "Book"
      )
    }
  )
}
composable(WELCOME_SCREEN.route) {
  selectedNavBarIndex = 0
  WelcomeScreen(...)
}
composable(
  MOVIE_SELECTION_SCREEN.route,
  ...
) { backStackEntry ->
  selectedNavBarIndex = 1

  MovieSelectionScreen(...)
}
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction Next: Conclusion