gpt4 book ai didi

android - 如何在 Jetpack Compose 中设置主题 `NavigationBar()` 和 `NavigationBarItem()`?

转载 作者:行者123 更新时间:2023-12-04 23:55:34 24 4
gpt4 key购买 nike

我很难尝试更改选定/未选定图标和 Activity 指示器的颜色。 docs没有示例或适当的 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.
)
)
}
}

最佳答案

使用 import androidx.compose.material3.Icon 作为您的图标。

你在这里混合 Material 和 material3 代码:Icon 是从 Material 导入并使用 Material LocalContentColor,另一方面 NavigationBarItem 是material3 View 并提供 material3 LocalContentColor

关于android - 如何在 Jetpack Compose 中设置主题 `NavigationBar()` 和 `NavigationBarItem()`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72082201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com