提问人:Saeed Noshadi 提问时间:11/18/2022 最后编辑:Gabriele MariottiSaeed Noshadi 更新时间:11/18/2022 访问量:2015
如何在 BottomBar jetpack compose 中删除选定的椭圆形项目颜色
how to remove selected oval item color in BottomBar jetpack compose
问:
我想删除所选项目后面的蓝色椭圆形颜色。 我该怎么做?
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()
)
)
答:
8赞
Gabriele Mariotti
11/18/2022
#1
指示器的颜色由 中的 indicatorColor
属性定义。
要删除它,您必须应用相同的 .NavigationBarItem
containerColor
NavigationBar
如果使用缺省值 ( = color),则必须计算应用于 .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)
)
)
在其他情况下,只需使用相同的颜色:
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 )
)
}
}
评论
2赞
Malik Bilal
5/22/2023
如何以这种方式消除涟漪效应?
评论
indicatorColor = Color.Transparent