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

Sae*_*adi 6 android android-jetpack-compose android-jetpack-compose-material3 material3

我想删除所选项目后面的蓝色椭圆形颜色。我怎样才能做到这一点?

 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()
        )
    )
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Gab*_*tti 10

indicatorColor指示器的颜色由NavigationBarItem.
要删除它,您必须应用containerColorNavigationBar.

如果您使用默认值(containerColor=surface颜色),则必须计算应用于不同高度的表面色调颜色containerColor

就像是:

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) 
        )
)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

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

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 )
        )
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 如何消除这种连锁反应呢? (2认同)