Guilherme Delgado
05/18/2021, 3:54 PMScaffold
with a BottomAppBar
(because I want the cutoutShape effect) and a few BottomNavigationItem
(this also happened when I had BottomNavigation
as a parent instead of BottomAppBar
) and the problem is there’s no “selected” effect on the menu items. I’ve checked and the var is being changed accordingly, but I see no UI change. To test it I did this (to my BottomNavigationItem
icon
and label
):
colorFilter = ColorFilter.tint(MaterialTheme.colors.onBackground.copy(alpha = if (isSelected) 1f else .5f)),
and it works.
What am I missing to get this working properly with the selected
property? Or the selected state is not meant for the item (icon and label)? ThanksLucien Guimaraes
05/18/2021, 4:56 PMLucien Guimaraes
05/18/2021, 4:57 PMBottomNavigationItem
you can use selectedContentColor
and unselectedContentColor
Lucien Guimaraes
05/18/2021, 4:57 PMBottomNavigationItem(
...
selectedContentColor = Green.darken1,
unselectedContentColor = Grey.lighten10,
)
Guilherme Delgado
05/18/2021, 4:59 PMLucien Guimaraes
05/18/2021, 5:01 PMBottomNavigationItem
implementation ?Guilherme Delgado
05/18/2021, 5:04 PMval isSelected = it.navCommand == navManager.commands.value
BottomNavigationItem(
icon = {
Image(
painter = painterResource(it.iconId),
contentDescription = it.navCommand.destination,
colorFilter = ColorFilter.tint(MaterialTheme.colors.onBackground),
)
},
label = {
Text(
text = stringResource(id = it.resourceId).uppercase(),
style = MaterialTheme.typography.caption,
color = MaterialTheme.colors.onBackground
)
},
selected = isSelected,
onClick = {
if (navManager.commands.value != it.navCommand) {
scope.launch { navManager.navigate(it.navCommand) }
}
}
)
Lucien Guimaraes
05/18/2021, 5:10 PMLucien Guimaraes
05/18/2021, 5:10 PMselectedContentColor = Green.darken1,
unselectedContentColor = Grey.lighten10,
Lucien Guimaraes
05/18/2021, 5:11 PMBottomNavigationItem(
icon = {
Image(
painter = painterResource(it.iconId),
contentDescription = it.navCommand.destination,
)
},
label = {
Text(
text = stringResource(id = it.resourceId).uppercase(),
style = MaterialTheme.typography.caption,
)
},
selected = isSelected,
onClick = {
if (navManager.commands.value != it.navCommand) {
scope.launch { navManager.navigate(it.navCommand) }
}
},
selectedContentColor = Color.Green,
unselectedContentColor = Color.Red,
)
Guilherme Delgado
05/18/2021, 5:12 PMGuilherme Delgado
05/18/2021, 5:13 PMLucien Guimaraes
05/18/2021, 5:21 PMLucien Guimaraes
05/18/2021, 5:22 PMLucien Guimaraes
05/18/2021, 5:22 PMicon = {
Icon(
painter = painterResource(it.iconId),
contentDescription = it.navCommand.destination,
)
},
Guilherme Delgado
05/19/2021, 8:34 AM