Skip to content

Commit 8c95dec

Browse files
Change fit system windows approach
1 parent 13e9844 commit 8c95dec

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/src/main/java/no/nordicsemi/android/common/test/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class MainActivity : NordicActivity() {
8181
override fun onCreate(savedInstanceState: Bundle?) {
8282
super.onCreate(savedInstanceState)
8383

84-
WindowCompat.setDecorFitsSystemWindows(window, false)
84+
setDecorFitsSystemWindows(false)
8585

8686
val menuItems = listOf(
8787
Item("Main", Tabs, Icons.Filled.Verified),

theme/src/main/java/no/nordicsemi/android/common/theme/NordicActivity.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ import android.os.Bundle
3737
import android.view.View
3838
import android.view.WindowInsetsController
3939
import androidx.activity.ComponentActivity
40+
import androidx.core.content.ContextCompat
4041
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
41-
import androidx.core.view.ViewCompat
42+
import androidx.core.view.WindowCompat
4243

4344
/**
4445
* Base activity that sets the Nordic theme and the Splash Screen.
@@ -56,6 +57,8 @@ abstract class NordicActivity : ComponentActivity() {
5657
setTheme(R.style.NordicTheme)
5758
super.onCreate(savedInstanceState)
5859

60+
setDecorFitsSystemWindows(true)
61+
5962
val view = window.decorView
6063
if (!isDarkMode()) {
6164
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
@@ -85,6 +88,15 @@ abstract class NordicActivity : ComponentActivity() {
8588
}
8689
}
8790

91+
fun setDecorFitsSystemWindows(decorFitsSystemWindows: Boolean) {
92+
if (!decorFitsSystemWindows) {
93+
WindowCompat.setDecorFitsSystemWindows(window, false)
94+
window.statusBarColor = ContextCompat.getColor(this, android.R.color.transparent)
95+
} else {
96+
window.statusBarColor = ContextCompat.getColor(this, R.color.statusBarColor)
97+
}
98+
}
99+
88100
fun isDarkMode(): Boolean {
89101
val darkModeFlag = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
90102
return darkModeFlag == Configuration.UI_MODE_NIGHT_YES

0 commit comments

Comments
 (0)