如何在 BottomBar jetpack compose 中删除选定的椭圆形项目颜色

how to remove selected oval item color in BottomBar jetpack compose

提问人:Saeed Noshadi 提问时间:11/18/2022 最后编辑:Gabriele MariottiSaeed Noshadi 更新时间:11/18/2022 访问量:2015

问:

我想删除所选项目后面的蓝色椭圆形颜色。 我该怎么做?

 NavigationBarItem(
        selected = selected,
        onClick = onClick,
        icon = if (selected) selectedIcon else icon,
        modifier = modifier,
        enabled = enabled,
        label = label,
        alwaysShowLabel = alwaysShowLabel,
        colors = NavigationBarItemDefaults.colors(
            selectedIconColor = AppDefaults.navigationSelectedItemColor(),
            unselectedIconColor = AppDefaults.navigationContentColor(),
            selectedTextColor = AppDefaults.navigationSelectedItemColor(),
            unselectedTextColor = AppDefaults.navigationContentColor(),
            indicatorColor = AppDefaults.navigationIndicatorColor()
        )
    )

enter image description here

安卓 android-jetpack-compose-material3 材料3

评论

0赞 Jan Bína 11/18/2022
你试过了吗?indicatorColor = Color.Transparent
0赞 Saeed Noshadi 11/18/2022
@JanBína 是的,它变为黑色

答:

8赞 Gabriele Mariotti 11/18/2022 #1

指示器的颜色由 中的 indicatorColor 属性定义。
要删除它,您必须应用相同的 .
NavigationBarItemcontainerColorNavigationBar

如果使用缺省值 ( = color),则必须计算应用于 .containerColorsurfacecontainerColor

像这样:

NavigationBarItem(
    icon = { androidx.compose.material3.Icon(Icons.Filled.Favorite, contentDescription = item) },
    label = { androidx.compose.material3.Text(item) },
    selected = selectedItem == index,
    onClick = { selectedItem = index },
    colors = androidx.compose.material3.NavigationBarItemDefaults
        .colors(
            selectedIconColor = Red,
            indicatorColor = MaterialTheme.colorScheme.surfaceColorAtElevation(LocalAbsoluteTonalElevation.current) 
        )
)

enter image description here

在其他情况下,只需使用相同的颜色:

NavigationBar(
    containerColor = Yellow
){

    items.forEachIndexed { index, item ->
        NavigationBarItem(
            icon = { androidx.compose.material3.Icon(Icons.Filled.Favorite, contentDescription = item) },
            label = { androidx.compose.material3.Text(item) },
            selected = selectedItem == index,
            onClick = { selectedItem = index },
            colors = androidx.compose.material3.NavigationBarItemDefaults
                .colors(
                    selectedIconColor = Red,
                    indicatorColor = Yellow )
        )
    }
}

enter image description here

评论

2赞 Malik Bilal 5/22/2023
如何以这种方式消除涟漪效应?