Avoid wrong system and navigation bar coloring

This commit is contained in:
Juha Heinanen
2026-04-03 19:27:48 +03:00
parent 3f5c28e8e2
commit f1ad2af9f4
2 changed files with 23 additions and 7 deletions

View File

@ -61,8 +61,6 @@ class MainActivity : ComponentActivity() {
@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
val extraAction = intent.getStringExtra("action")

View File

@ -2,6 +2,9 @@ package com.tutpro.baresip
import android.app.Activity
import android.os.Build.VERSION
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
@ -103,13 +106,28 @@ fun AppTheme(
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
val activity = view.context as? ComponentActivity
if (activity != null) {
activity.enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(
android.graphics.Color.TRANSPARENT,
android.graphics.Color.TRANSPARENT,
) { isDark },
navigationBarStyle = SystemBarStyle.auto(
android.graphics.Color.TRANSPARENT,
android.graphics.Color.TRANSPARENT,
) { isDark }
)
} else {
val window = (view.context as Activity).window
val insetsController = WindowCompat.getInsetsController(window, view)
val isBackgroundEffectivelyLight = ColorUtils.calculateLuminance(colorScheme.background.toArgb()) > 0.5
val isBackgroundEffectivelyLight =
ColorUtils.calculateLuminance(colorScheme.background.toArgb()) > 0.5
insetsController.isAppearanceLightStatusBars = isBackgroundEffectivelyLight
insetsController.isAppearanceLightNavigationBars = isBackgroundEffectivelyLight
}
}
}
MaterialTheme(
colorScheme = colorScheme,