@@ -18,6 +18,7 @@ package com.example.superheroes.ui.theme
1818
1919import android.app.Activity
2020import android.os.Build
21+ import android.view.View
2122import androidx.compose.foundation.isSystemInDarkTheme
2223import androidx.compose.material3.MaterialTheme
2324import androidx.compose.material3.darkColorScheme
@@ -26,6 +27,7 @@ import androidx.compose.material3.dynamicLightColorScheme
2627import androidx.compose.material3.lightColorScheme
2728import androidx.compose.runtime.Composable
2829import androidx.compose.runtime.SideEffect
30+ import androidx.compose.ui.graphics.Color
2931import androidx.compose.ui.graphics.toArgb
3032import androidx.compose.ui.platform.LocalContext
3133import androidx.compose.ui.platform.LocalView
@@ -115,9 +117,7 @@ fun SuperheroesTheme(
115117 val view = LocalView .current
116118 if (! view.isInEditMode) {
117119 SideEffect {
118- val window = (view.context as Activity ).window
119- window.statusBarColor = colorScheme.background.toArgb()
120- WindowCompat .getInsetsController(window, view).isAppearanceLightStatusBars = ! darkTheme
120+ setUpEdgeToEdge(view,darkTheme)
121121 }
122122 }
123123
@@ -128,3 +128,24 @@ fun SuperheroesTheme(
128128 content = content
129129 )
130130}
131+
132+ /* *
133+ * Sets up edge-to-edge for the window of this [view]. The system icon colors are set to either
134+ * light or dark depending on whether the [darkTheme] is enabled or not.
135+ */
136+ private fun setUpEdgeToEdge (view : View , darkTheme : Boolean ) {
137+ val window = (view.context as Activity ).window
138+ WindowCompat .setDecorFitsSystemWindows(window, false )
139+ window.statusBarColor = Color .Transparent .toArgb()
140+ val navigationBarColor = if (Build .VERSION .SDK_INT >= 26 ) {
141+ Color .Transparent .toArgb()
142+ }
143+ else {
144+ // Min sdk version for this app is 24, this block is for SDK versions 24 and 25
145+ Color (0x63000000 ).toArgb()
146+ }
147+ window.navigationBarColor = navigationBarColor
148+ val controller = WindowCompat .getInsetsController(window, view)
149+ controller.isAppearanceLightStatusBars = ! darkTheme
150+ controller.isAppearanceLightNavigationBars = ! darkTheme
151+ }
0 commit comments