【问题标题】:Jetpack Compose. selectedContentColor and unselectedContentColor not working in BottomNavigationItem喷气背包组成。 selectedContentColor 和 unselectedContentColor 在 BottomNavigationItem 中不起作用
【发布时间】:2022-10-20 18:17:36
【问题描述】:

我有代码:

@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
                    }
                }
            )
        }
    }
}

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

【问题讨论】:

    标签: navigation android-jetpack-compose bottom-navigation-bar


    【解决方案1】:

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

    import androidx.compose.material3.Icon
    import androidx.compose.material3.Text
    

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

    import androidx.compose.material.Icon
    import androidx.compose.material.Text
    

    【讨论】:

      猜你喜欢
      • 2022-06-17
      • 1970-01-01
      • 2022-06-12
      • 2021-11-22
      • 2021-10-27
      • 1970-01-01
      • 2019-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多