[英]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.