透明导航栏留下暗框
transparent navigation bar leaves a dark box
@Composable
fun BottomNavigationBar(items: List<BottomNavItem>, navController: NavController, onItemClick: (BottomNavItem) -> Unit){
val selectedScreen = navController.currentBackStackEntryAsState()
BottomNavigation(
modifier = Modifier.fillMaxWidth(),
backgroundColor = Color.Transparent,
) {
items.forEach { item ->
val selected = item.route == selectedScreen.value?.destination?.route
BottomNavigationItem(
selected = selected,
onClick = { onItemClick(item) },
selectedContentColor = colorResource(id = R.color.button_background_light_blue),
unselectedContentColor = Color.Gray,
icon = {
Column(horizontalAlignment = CenterHorizontally) {
Icon(imageVector = item.icon, contentDescription = item.name)
if(selected) {
Text(text = item.name, textAlign = TextAlign.Center, fontSize = 10.sp)
}
}
}
)
}
}
}
顺便说一句,我还没有找到任何关于(这正是我的假设)包含图标或任何类似内容的框,我可以添加什么来删除那个“框”?
只需将海拔设置为 0.dp。我不知道 BottomNavigation
的确切方法,但如果有一个名为 elevation
的参数,请将其设置为 0.dp。如果没有具有该名称的参数值,请应用海拔修饰符。
Modifier.elevation(0.dp)
@Composable
fun BottomNavigationBar(items: List<BottomNavItem>, navController: NavController, onItemClick: (BottomNavItem) -> Unit){
val selectedScreen = navController.currentBackStackEntryAsState()
BottomNavigation(
modifier = Modifier.fillMaxWidth(),
backgroundColor = Color.Transparent,
) {
items.forEach { item ->
val selected = item.route == selectedScreen.value?.destination?.route
BottomNavigationItem(
selected = selected,
onClick = { onItemClick(item) },
selectedContentColor = colorResource(id = R.color.button_background_light_blue),
unselectedContentColor = Color.Gray,
icon = {
Column(horizontalAlignment = CenterHorizontally) {
Icon(imageVector = item.icon, contentDescription = item.name)
if(selected) {
Text(text = item.name, textAlign = TextAlign.Center, fontSize = 10.sp)
}
}
}
)
}
}
}
顺便说一句,我还没有找到任何关于(这正是我的假设)包含图标或任何类似内容的框,我可以添加什么来删除那个“框”?
只需将海拔设置为 0.dp。我不知道 BottomNavigation
的确切方法,但如果有一个名为 elevation
的参数,请将其设置为 0.dp。如果没有具有该名称的参数值,请应用海拔修饰符。
Modifier.elevation(0.dp)