Jetpack 撰写。selectedContentColor 和 unselectedContentColor 在 BottomNavigationItem 中不起作用

Ale*_*lex 2 navigation android-jetpack-compose bottom-navigation-bar

我有代码:

@Composable
fun BottomNavigationBar(navController: NavController) {
    val items = listOf(
        BottomNavigationItem.One,
        BottomNavigationItem.Two,
        BottomNavigationItem.Three,
        BottomNavigationItem.Four,
        BottomNavigationItem.Five
    )
    BottomNavigation(
        backgroundColor = colorResource(id = R.color.teal_700),
        contentColor = Color.White
    ) {
        val navBackStackEntry by navController.currentBackStackEntryAsState()
        val currentRoute = navBackStackEntry?.destination?.route
        items.forEach { item ->
            BottomNavigationItem(
                icon = { Icon(painterResource(id = item.icon), contentDescription = item.title) },
                label = { Text(text = item.title) },
                selectedContentColor = Color.White,
                unselectedContentColor = Color.White.copy(0.4f),
                alwaysShowLabel = true,
                selected = currentRoute == item.route,
                onClick = {
                    navController.navigate(item.route) {
                        navController.graph.startDestinationRoute?.let { route ->
                            popUpTo(route) {
                                saveState = true
                            }
                        }
                        launchSingleTop = true
                        restoreState = true
                    }
                }
            )
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但 contentColor 和 selectedContentColor 与 unselectedContentColor 不起作用。所选项目没有改变颜色(其他项目没有 unselectedContentColor)

Ale*_*lex 14

我发现了错误(或者,也许这是正确的情况),但是如果你有

import androidx.compose.material3.Icon
import androidx.compose.material3.Text
Run Code Online (Sandbox Code Playgroud)

属性 selectedContentColor 和 unselectedContentColor 将不起作用。您必须使用以下导入:

import androidx.compose.material.Icon
import androidx.compose.material.Text
Run Code Online (Sandbox Code Playgroud)