我正在创建一个带有底部导航栏的简单应用程序。我想要在组合屏幕中向下滚动时隐藏底部导航栏,并在向上滚动时显示它。
任何帮助都将不胜感激。如果需要更多代码,请告诉我。我已经附上了我认为与此问题相关的所有代码。
这是我的底部导航栏。
任何帮助都将不胜感激。如果需要更多代码,请告诉我。我已经附上了我认为与此问题相关的所有代码。
这是我的底部导航栏。
@Composable
fun BottomBar(navController: NavController) {
val items = listOf(
NavigationItem.Home,
NavigationItem.Search
)
BottomNavigation(
backgroundColor = MaterialTheme.colors.DarkRed,
contentColor = Color.White
) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route
items.forEach { item ->
BottomNavigationItem(
selected = currentRoute == item.route,
icon = {
Icon(
imageVector = item.icon,
contentDescription = "Icon",
modifier = Modifier.size(28.dp)
)
},
alwaysShowLabel = false,
selectedContentColor = Color.White,
unselectedContentColor = Color.White.copy(0.4f),
onClick = {
navController.navigate(item.route){
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
navController.graph.startDestinationRoute?.let{route ->
popUpTo(route){
saveState = true
}
}
// Avoid multiple copies of the same destination when
// reselecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
restoreState = true
}
}
)
}
}
}
这是我的主屏幕
@Composable
fun MainScreen(){
val navController = rememberNavController()
Scaffold(topBar = {
ActionBar("Books")
},
bottomBar = {
BottomBar(navController)
}){
NavigationGraph(navController = navController)
}
}
而这个NavigationGraph
@Composable
fun NavigationGraph(navController: NavHostController){
NavHost(navController = navController, startDestination = NavigationItem.Home.route ){
composable(NavigationItem.Home.route){
HomeScreen()
}
composable(NavigationItem.Search.route){
SearchScreen()
}
}
}