我如何主题`navigationbar()和`navigationbariTem() 我在尝试更改所选/未选择图标的颜色和活动指示器的颜色非常困难。这些文档没有示例或适当的kdocs,我似乎找不到任何示例

问题描述 投票:0回答:2

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..
    
android material-ui android-jetpack-compose material-you android-jetpack-compose-material3
2个回答
6
投票
LocalContentColor

路线的方式。 这是这样宣布的:

NavigationBarItem

这是错误的,

LocalContentColor
变量必须是一个状态:
NavBackStackEntry
,因此,
val navBackStackEntry = controller.currentBackStackEntry
val currentRoute = navBackStackEntry?.destination?.route
参数按预期工作。

希望这可以帮助遇到这个愚蠢问题的人。 😅

0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.