From 247bb28c4b91277be764866cc47a7e1247c39a7f Mon Sep 17 00:00:00 2001 From: MagicalMeghan Date: Tue, 27 Jun 2023 17:16:00 -0400 Subject: [PATCH 1/2] edge to edge --- .../java/com/example/woof/ui/theme/Theme.kt | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/woof/ui/theme/Theme.kt b/app/src/main/java/com/example/woof/ui/theme/Theme.kt index 2f5d87a..d81e255 100644 --- a/app/src/main/java/com/example/woof/ui/theme/Theme.kt +++ b/app/src/main/java/com/example/woof/ui/theme/Theme.kt @@ -17,6 +17,8 @@ package com.example.woof.ui.theme import android.app.Activity import android.os.Build +import android.view.View +import android.view.WindowManager import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme @@ -25,6 +27,7 @@ import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView @@ -114,9 +117,7 @@ fun WoofTheme( val view = LocalView.current if (!view.isInEditMode) { SideEffect { - val window = (view.context as Activity).window - window.statusBarColor = colorScheme.primary.toArgb() - WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + setUpEdgeToEdge(view, darkTheme) } } @@ -127,3 +128,32 @@ fun WoofTheme( content = content ) } + +/** + * Sets up edge-to-edge for the window of this [view]. The system icon colors are set to either + * light or dark depending on whether the [darkTheme] is enabled or not. + */ +private fun setUpEdgeToEdge(view: View, darkTheme: Boolean) { + val window = (view.context as Activity).window + WindowCompat.setDecorFitsSystemWindows(window, false) + window.statusBarColor = Color.Transparent.toArgb() + if (Build.VERSION.SDK_INT >= 29) { + window.statusBarColor = Color.Transparent.toArgb() + window.navigationBarColor = Color.Transparent.toArgb() + } else if (Build.VERSION.SDK_INT >= 26) { + window.statusBarColor = Color.Transparent.toArgb() + window.navigationBarColor = Color(0xFF, 0xFF, 0xFF, 0x63).toArgb() + } else if (Build.VERSION.SDK_INT >= 23) { + window.statusBarColor = Color.Transparent.toArgb() + @Suppress("DEPRECATION") + window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) + } else { + @Suppress("DEPRECATION") + window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) + @Suppress("DEPRECATION") + window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) + } + val controller = WindowCompat.getInsetsController(window, view) + controller.isAppearanceLightStatusBars = !darkTheme + controller.isAppearanceLightNavigationBars = !darkTheme +} From 31fa149d8ab1f73ae1a781d3f300cc96bd713150 Mon Sep 17 00:00:00 2001 From: MagicalMeghan Date: Thu, 13 Jul 2023 15:13:13 -0400 Subject: [PATCH 2/2] simplifying edge to edge --- .../java/com/example/woof/ui/theme/Theme.kt | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/example/woof/ui/theme/Theme.kt b/app/src/main/java/com/example/woof/ui/theme/Theme.kt index d81e255..8aa36b5 100644 --- a/app/src/main/java/com/example/woof/ui/theme/Theme.kt +++ b/app/src/main/java/com/example/woof/ui/theme/Theme.kt @@ -18,7 +18,6 @@ package com.example.woof.ui.theme import android.app.Activity import android.os.Build import android.view.View -import android.view.WindowManager import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme @@ -65,7 +64,6 @@ private val LightColors = lightColorScheme( scrim = md_theme_light_scrim, ) - private val DarkColors = darkColorScheme( primary = md_theme_dark_primary, onPrimary = md_theme_dark_onPrimary, @@ -137,22 +135,13 @@ private fun setUpEdgeToEdge(view: View, darkTheme: Boolean) { val window = (view.context as Activity).window WindowCompat.setDecorFitsSystemWindows(window, false) window.statusBarColor = Color.Transparent.toArgb() - if (Build.VERSION.SDK_INT >= 29) { - window.statusBarColor = Color.Transparent.toArgb() - window.navigationBarColor = Color.Transparent.toArgb() - } else if (Build.VERSION.SDK_INT >= 26) { - window.statusBarColor = Color.Transparent.toArgb() - window.navigationBarColor = Color(0xFF, 0xFF, 0xFF, 0x63).toArgb() - } else if (Build.VERSION.SDK_INT >= 23) { - window.statusBarColor = Color.Transparent.toArgb() - @Suppress("DEPRECATION") - window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) - } else { - @Suppress("DEPRECATION") - window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) - @Suppress("DEPRECATION") - window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) + val navigationBarColor = when { + Build.VERSION.SDK_INT >= 29 -> Color.Transparent.toArgb() + Build.VERSION.SDK_INT >= 26 -> Color(0xFF, 0xFF, 0xFF, 0x63).toArgb() + // Min sdk version for this app is 24, this block is for SDK versions 24 and 25 + else -> Color(0x00,0x00, 0x00, 0x50).toArgb() } + window.navigationBarColor = navigationBarColor val controller = WindowCompat.getInsetsController(window, view) controller.isAppearanceLightStatusBars = !darkTheme controller.isAppearanceLightNavigationBars = !darkTheme