找不到同时使用底部 sheet 和 android 中的底部导航栏的方法
Cannot find a way to use both at same time, bottom sheet and bottom navigation bar in android compose
在 android compose 中,有 Scaffold
可组合函数用于创建包含底部导航栏的布局,还有另一个名为 BottomSheetScaffold
的函数用于创建包含底部导航栏的布局酒吧。
我的问题是如何在同一布局中实现底部 sheet 和底部导航栏?
我尝试使用 BottomSheetScaffold 并在布局中添加底部导航栏,但是当我在同一列中使用 NavHost 时失败了。
案例的简化代码:
BottomSheetScaffold(
{ BottomSheetComposable },
topBar = {
TopAppBar()
},
sheetPeekHeight = 0.dp
) {
Column() {
NavHost(
navController,
startDestination = "route"
) {
Composable("route") {}
}
Box(
modifier = Modifier
.fillMaxWidth()
.height(60.dp)
) {
BottomNavigationBar()
}
}
}
临时解决方案是在 BottomSheetScaffold
内容
中使用 scaffold
BottomSheetScaffold(
sheetShape = BottomSheetShape,
sheetContent = {
currentBottomSheetScreen?.let {
MainBottomSheetLayout(
it, navController, textToSpeech,
closeSheet
)
}
}) {
Scaffold(
topBar = { LinguisticTopAppBar(navController, mainViewModel, openSheet) },
bottomBar = {
BottomNavigationBar(mainViewModel, navController)
},
) {
Column(modifier = Modifier.padding(it)) {
MainContent(
navController,
mainViewModel,
openSheet
)
}
}
}
在 android compose 中,有 Scaffold
可组合函数用于创建包含底部导航栏的布局,还有另一个名为 BottomSheetScaffold
的函数用于创建包含底部导航栏的布局酒吧。
我的问题是如何在同一布局中实现底部 sheet 和底部导航栏?
我尝试使用 BottomSheetScaffold 并在布局中添加底部导航栏,但是当我在同一列中使用 NavHost 时失败了。
案例的简化代码:
BottomSheetScaffold(
{ BottomSheetComposable },
topBar = {
TopAppBar()
},
sheetPeekHeight = 0.dp
) {
Column() {
NavHost(
navController,
startDestination = "route"
) {
Composable("route") {}
}
Box(
modifier = Modifier
.fillMaxWidth()
.height(60.dp)
) {
BottomNavigationBar()
}
}
}
临时解决方案是在 BottomSheetScaffold
内容
scaffold
BottomSheetScaffold(
sheetShape = BottomSheetShape,
sheetContent = {
currentBottomSheetScreen?.let {
MainBottomSheetLayout(
it, navController, textToSpeech,
closeSheet
)
}
}) {
Scaffold(
topBar = { LinguisticTopAppBar(navController, mainViewModel, openSheet) },
bottomBar = {
BottomNavigationBar(mainViewModel, navController)
},
) {
Column(modifier = Modifier.padding(it)) {
MainContent(
navController,
mainViewModel,
openSheet
)
}
}
}