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...)
Asked
Active
Viewed 96 times
2
-
You should look this: https://stackoverflow.com/questions/37672833/android-m-light-and-dark-status-bar-programmatically-how-to-make-it-dark-again/39596725#39596725 – Halil Ozel May 07 '23 at 14:58
1 Answers
0
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
}

Code Poet
- 6,222
- 2
- 29
- 50