Reputation: 2846
How to change the status bar default text color in Android - Jetpack composes, Change the status bar text color from White to Black (Time, Wifi and network icon, etc...)
Upvotes: 4
Views: 818
Reputation: 8013
You could do it like this:
setContent {
MyTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
val systemUiController = rememberSystemUiController()
val useDarkIcons = !isSystemInDarkTheme()
SideEffect {
systemUiController.setStatusBarColor(
color = Color(0xff655D8A),
darkIcons = !useDarkIcons
)
}
}
}
Basically, use dark icons if system is not in dark theme.
Another possibility is to get the luminance of your status bar.
fun isDark(color: Int): Boolean {
return ColorUtils.calculateLuminance(color) < 0.5
}
And use it like this for example:
fun getTextColor(accentColor: Int): Color {
val color =
if (isDark(accentColor)) {
Color.White
} else {
Color.DarkGray
}
return color
}
Upvotes: 0