So I've been playing around a little with edge to edge, and according to the official Android documentation they show that you can force the status bar icons to show up as dark by using...
WindowCompat.getInsetsController(window, window.decorView)
.isAppearanceLightStatusBars = true
So I gave that a shot in my app and the status bar icons are still showing as light, which is making the icons sort of invisible in my app, since I am using the surface color with a scaffold. I do want the app color to extend behind the status bar, but the icons need to be black, or at least the dark color.
A very simple example of what I mean is...
class MainActivity: FragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
WindowCompat.getInsetsController(window, window.decorView)
.isAppearanceLightStatusBars = true
setContent {
StatusBarTestTheme {
Surface(color = MaterialTheme.colorScheme.surface) {
Scaffold(...) { padding ->
HomeView(padding)
}
}
}
}
}
@Composable
fun HomeView(padding: PaddingValues) {
Box(modifier = Modifier.padding(padding) {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text("Hello There")
}
}
}
When you do that, if the device theme is in light mode the status bar icons are white, it doesn't seem to take the `isAppearanceLightStatusBars = true` into effect at all. If I switch the device to dark mode, then the icons are black, but I need them to always be black.
The documentation I'm looking at is on the official android developer page here...
https://developer.android.com/develop/ui/compose/system/setup-e2e
I found the issue. The issue was I was putting that code in MainActivity, since I thought that's where the it should be, since I wanted it system wide. The solution was to put the code into the Composable... the "HomeView" from the above code...
@Composable
fun HomeView() {
val context = LocalContext.current
SideEffect {
val window = (context as Activity).window
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightStatusBats = true
}
//display code
}
I also added some code that checks for system dark theme and then changes the status icons to be the opposite...
@Composable
fun HomeView() {
val context = LocalContext.current
val useBlackIcons = isSystemInDarkTheme()
SideEffect {
val window = (context as Activity).window
WindowInsetsControllerCompat(window, window.decorView)
.isAppearanceLightStatusBars = !useBlackIcons
}
//View Code Here
}
Not sure if anyone else runs into this or not, but thought I would post the answer instead of just closing the question. If anyone feels like it should be deleted let me know and I'll just delete the question.