Skip to content

Commit e83dfb6

Browse files
committed
Simplified edge to edge
1 parent 63fcef2 commit e83dfb6

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

  • app/src/main/java/com/example/superheroes/ui/theme

app/src/main/java/com/example/superheroes/ui/theme/Theme.kt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.example.superheroes.ui.theme
1818

1919
import android.app.Activity
2020
import android.os.Build
21+
import android.view.View
2122
import androidx.compose.foundation.isSystemInDarkTheme
2223
import androidx.compose.material3.MaterialTheme
2324
import androidx.compose.material3.darkColorScheme
@@ -26,6 +27,7 @@ import androidx.compose.material3.dynamicLightColorScheme
2627
import androidx.compose.material3.lightColorScheme
2728
import androidx.compose.runtime.Composable
2829
import androidx.compose.runtime.SideEffect
30+
import androidx.compose.ui.graphics.Color
2931
import androidx.compose.ui.graphics.toArgb
3032
import androidx.compose.ui.platform.LocalContext
3133
import 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

Comments
 (0)