NavigationBar(
containerColor = NavBarColor,
contentColor = ContentColor, // <-- Can't tell what this is for.
modifier = Modifier
.align(Alignment.BottomCenter)
) {
// ...
destinations.forEachIndexed { index, item ->
NavigationBarItem(
selected = currentDestination?.hierarchy?.any { it.route == item.route } == true,
onClick = {
// ...
},
icon = {
when (index) {
0 -> {
Icon(
imageVector = Icons.Rounded.Add,
contentDescription = stringResource(id = item.description)
)
}
1 -> {
Icon(
imageVector = Icons.Rounded.Home,
contentDescription = stringResource(id = item.description)
)
}
2 -> {
Icon(
imageVector = Icons.Rounded.Call,
contentDescription = stringResource(id = item.description)
)
}
}
},
// Why on Earth does this not want to work:
colors = NavigationBarItemDefaults.colors(
selectedIconColor = NavBarColor, // <-- This doesn't work.
unselectedIconColor = ContentColor, // <-- This doesn't work.
indicatorColor = ContentColor // <-- This works.
)
)
}
}
使用您的图标。 您在此处将混合材料和材料3代码:
import androidx.compose.material3.Icon
从材料中导入并使用材料Icon
,另一方面是材料3视图3..
LocalContentColor
路线的方式。 这是这样宣布的:
NavigationBarItem
这是错误的,
LocalContentColor
变量必须是一个状态:NavBackStackEntry
,因此,val navBackStackEntry = controller.currentBackStackEntry
val currentRoute = navBackStackEntry?.destination?.route
参数按预期工作。
希望这可以帮助遇到这个愚蠢问题的人。 😅