指示器的颜色由以下定义indicatorColor
属性中的NavigationBarItem
.
要删除它,您必须应用相同的containerColor
所使用的NavigationBar
.
如果您使用默认值(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 )
)
}
}