@@ -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,23 @@ 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 = when {
141+ Build .VERSION .SDK_INT >= 29 -> Color .Transparent .toArgb()
142+ Build .VERSION .SDK_INT >= 26 -> Color (0xFF , 0xFF , 0xFF , 0x63 ).toArgb()
143+ // Min sdk version for this app is 24, this block is for SDK versions 24 and 25
144+ else -> Color (0x00 , 0x00 , 0x00 , 0x50 ).toArgb()
145+ }
146+ window.navigationBarColor = navigationBarColor
147+ val controller = WindowCompat .getInsetsController(window, view)
148+ controller.isAppearanceLightStatusBars = ! darkTheme
149+ controller.isAppearanceLightNavigationBars = ! darkTheme
150+ }
0 commit comments