简体   繁体   English

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

[英]how to remove selected oval item color in BottomBar jetpack compose

I want to remove the blue oval color behind the selected item.我想删除所选项目后面的蓝色椭圆形颜色。 How can I do that?我怎样才能做到这一点?

 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()
        )
    )

在此处输入图像描述

The color of the indicator is defined by the indicatorColor attribute in the NavigationBarItem .指示器的颜色由NavigationBarItem中的indicatorColor属性定义。
To remove it you have to apply the same containerColor used by the NavigationBar .要删除它,您必须应用NavigationBar使用的相同containerColor

If you are using the default ( containerColor = surface color) you have to calculate the surface tonal color at different elevation applied to the containerColor .如果您使用默认值( containerColor = surface颜色),则必须计算应用于containerColor的不同高度的表面色调颜色。

Something like:就像是:

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

在此处输入图像描述

In the other cases just use the same color:在其他情况下,只需使用相同的颜色:

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

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM