Created a simple Jetpack Compose app straight out of the Android Studio template and added a bottom navigation bar. Did not specify/override any color anywhere. However, bottom nav bar labels show black-on-purple. I did not change ui/theme/Color.kt. Dark mode not enabled in the device.
I need to change the label text color contrasting to the background (depending up light/dark mode etc.). Where and how do I configure this?
Manifest refers to theme:
<style name="Theme.MyApp" parent="android:Theme.Material.Light.NoActionBar" />
Here is the code:
setContent {
MyAppTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
val homeViewModel: HomeViewModel by viewModels()
val navController = rememberNavController()
val items = listOf(
Screen.Home,
Screen.Profile,
)
Scaffold(
bottomBar = {
BottomNavigation {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
items.forEach { screen ->
BottomNavigationItem(
icon = { Icon(screen.icon, contentDescription = null) },
label = {
Text(
stringResource(screen.resourceId),
style = Typography.labelSmall
)
},
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
onClick = {
navController.navigate(screen.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
},
)
}
}
}
)
}
}
}
First you need to define/support dynamic theme in your compose app:
Now apply this MainAppTheme in place of
MyAppTheme
: