Adeel Malik
03/01/2023, 12:26 PMNavigationBarItem
with Material 3 in jetpack compose project. I don’t want to have this box-like effect when nav item is selected. What is this called and how do i go about removing it? 🙏Adeel Malik
03/01/2023, 12:30 PM@Composable
fun BottomNavigationContainer(
navController: NavController,
viewModel: MainViewModelContract
) {
val items = listOf(
NavItem.Home,
NavItem.Discover,
NavItem.Contracts,
NavItem.Card,
<http://NavItem.Shop|NavItem.Shop>
)
NavigationBar(containerColor = White) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route
items.forEach { item ->
NavigationBarItem(
icon = {
Icon(
painterResource(id = item.icon),
contentDescription = stringResource(id = item.title),
modifier = Modifier.size(30.dp),
)
},
label = {
Text(
text = stringResource(id = item.title),
fontSize = 10.sp
)
},
alwaysShowLabel = true,
selected = currentRoute == item.navigation.name,
onClick = {
navControllerOnClick(
navController = navController,
navName = item.navigation.name,
extraOnClickAction = {
viewModel.subNavigationClicked(item.navigation)
}
)
},
colors = NavigationBarItemDefaults.colors(
selectedIconColor = BottomNavIconSelectedColor,
selectedTextColor = BottomNavIconSelectedColor,
unselectedIconColor = BottomNavIconUnSelectedColor,
unselectedTextColor = BottomNavIconUnSelectedColor
)
)
}
}
}
Stylianos Gakis
03/01/2023, 12:48 PMcolors = NavigationBarItemDefaults.colors(
selectedIconColor = BottomNavIconSelectedColor,
selectedTextColor = BottomNavIconSelectedColor,
unselectedIconColor = BottomNavIconUnSelectedColor,
unselectedTextColor = BottomNavIconUnSelectedColor
)
is a way to change what the colors are when it’s highlighted. One thing you can do is have the selected color be the same as the background color, so it simply won’t look any different.
If you need a very different style all together in the future, it may be worth it to build your own composable for it, or to make your life easier, copy over the code from material3 and adjust it to your liking.Adeel Malik
03/01/2023, 1:24 PMindicatorColor = White
@Stylianos Gakis Thanks 👍 Changing to same background color works. But it also have a small fade out type animation which shows with different color when NavItem gets selected. But i guess, i can live with that.Stylianos Gakis
03/01/2023, 1:28 PMNavigationBarItem
already is. You can dig into the code a bit and try and find it.zt
03/01/2023, 4:42 PMandrew
03/01/2023, 5:20 PMdorche
03/01/2023, 6:54 PMAdeel Malik
03/01/2023, 9:20 PMMutableInteractionSource
class