ima*_*ke_ 4 android material-ui android-jetpack-compose material-you android-jetpack-compose-material3
我很难尝试更改选定/未选定图标和活动指示器的颜色。这些文档没有示例或正确的 Kdocs,而且我似乎无法在网上找到任何示例(请向我指出您知道的任何示例)。图标只是不改变颜色并保持黑色。
我的NavigationBar看起来像这样:
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.
)
)
}
}
Run Code Online (Sandbox Code Playgroud)
用于import androidx.compose.material3.Icon您的图标。
您在这里混合了材质和材质3代码:Icon从材质导入并使用材质LocalContentColor,另一方面NavigationBarItem是材质3视图并提供材质3 LocalContentColor。