Luca Nicoletti
07/06/2023, 12:25 PMBottomNavigationBar
as follow:
BottomNavigation(
Modifier
.fillMaxWidth()
.height(64.dp),
backgroundColor = Colors.surface,
) {
items.forEach { screen ->
val selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true
BottomNavigationItem(
icon = { Icon(painterResource(screen.getIcon()), contentDescription = null) },
selected = selected,
selectedContentColor = Color.Blue,
unselectedContentColor = Color.Cyan,
label = {
Text(text = stringResource(id = screen.label), fontSize = 11.sp, color = Color.Gray)
},
onClick = { onClick(screen) }
)
}
}
But this doesn’t colour (both selected & unselected are ignored) the icons, what am I doing wrong?
selected
is calculated correctly for every itemLuca Nicoletti
07/06/2023, 12:45 PMval color = if (selected) {
Colors.bottomBarSelectedColor
} else {
Colors.gray
}
BottomNavigationItem(
icon = { Icon(painterResource(id = screen.getIcon()), null, tint = color) },
This works, but I would expect it to work out of the box? Am I missing something? 🙂Stylianos Gakis
07/06/2023, 1:14 PMBottomNavigationItem
come from? What does it do with the colors inside there when it’s passed?
Could it be smth silly like using the LocalContentColor from material2 while you’re using the Icon from material3 so it doesn’t pick the composition local correctly for the tint parameter?Luca Nicoletti
07/06/2023, 1:19 PMpackage androidx.compose.materi
Luca Nicoletti
07/06/2023, 1:22 PMStylianos Gakis
07/06/2023, 1:26 PMLuca Nicoletti
07/06/2023, 1:33 PMStylianos Gakis
07/06/2023, 1:37 PMLocalContentColor
.
And then Icon here takes that LocalContentColor to decide what the tint is.
So my guess it you’re using Icon from material3. The only other explanation would be that your icon isn’t able to be tinted correctly, but it doesn’t seem the case since specifically chosing the right color does seem to work for you.
So check if you do import androidx.compose.material3.Icon
in that file.Luca Nicoletti
07/06/2023, 1:39 PMLuca Nicoletti
07/06/2023, 1:39 PMStylianos Gakis
07/06/2023, 1:44 PM