And*_*Yao 5 android android-jetpack material-components-android android-jetpack-compose
BottomAppBar我在 Jetpack Compose 应用程序中使用 Material作为底部导航。但是当我尝试将我的 fab 停靠在 上时BottomAppBar,它覆盖了导航项,如屏幕截图所示。有什么办法可以在晶圆厂旁边自动添加空间吗?

我想实现这种效果,而不需要Space手动在导航项之间添加,如下图所示:

下面是我的代码:
@Composable
fun TestApp() {
val navController = rememberNavController()
Scaffold(
bottomBar = {
MyBottomAppBar(navController = navController)
},
floatingActionButton = {
FloatingActionButton(onClick = { }) {
Icon(imageVector = Icons.Rounded.Add, contentDescription = "fab")
}
},
floatingActionButtonPosition = FabPosition.Center,
isFloatingActionButtonDocked = true,
) {
NavHost(navController, startDestination = Screen.Bill.route) {
composable(Screen.Bill.route) { BillScreen() }
composable(Screen.Chart.route) { ChartScreen() }
composable(Screen.Budget.route) { BudgetScreen() }
composable(Screen.Account.route) { AccountScreen() }
}
}
}
Run Code Online (Sandbox Code Playgroud)
@Composable
fun MyBottomAppBar(navController: NavController) {
BottomAppBar(
cutoutShape = CircleShape
) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.arguments?.getString(KEY_ROUTE)
Screen.items.forEachIndexed { index, screen ->
BottomNavigationItem(
selected = (currentRoute == screen.route),
icon = { Icon(screen.iconRes, screen.route) },
label = { Text(stringResource(id = screen.labelRes)) },
onClick = {
navController.navigate(screen.route) {
popUpTo = navController.graph.startDestination
launchSingleTop = true
}
}
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
Gab*_*tti 10
is BottomNavigationaRow并且所有 the BottomNavigationItemis都Box带有.weight(1f)修饰符RowScope。
您可以在中间添加一个“空”元素,Row或者BottomNavigation与BottomNavigationItem.
例如:
bottomBar = {
BottomAppBar(cutoutShape = fabShape) {
BottomNavigation {
items.forEachIndexed { index, item ->
if (index != 2){ //
BottomNavigationItem(
// your implementation
)} else {
//Empty BottomNavigationItem
BottomNavigationItem(
icon = {},
label = { },
selected = false,
onClick = { },
enabled = false
)
}
}
}
}
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2263 次 |
| 最近记录: |