我在 Jetpack Compose 应用程序的项目中设置了一个带有 2 个目的地的底部栏。我尝试遵循谷歌的示例。
例如,它看起来像这样:
@Composable
fun ExampleBottomBar(navController: NavHostController) {
val items = listOf(
BottomNavigationGraph.Graph1,
BottomNavigationGraph.Graph2
)
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
BottomNavigation {
items.forEach { screen ->
BottomNavigationItem(
onClick = {
navController.navigate(screen.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
},
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
icon = { Icon(imageVector = screen.icon, contentDescription = null) },
label = { Text(stringResource(screen.label)) }
)
} …Run Code Online (Sandbox Code Playgroud) android android-navigation android-architecture-navigation android-jetpack-compose jetpack-compose-navigation