Hayk
04/18/2025, 11:14 AMisSystemInDarkTheme()
is just used for colors.
For the drawables, I should use AppCompatDelegate.setDefaultNightMode.
But for now, it breaks my app UI on Android 35. Idk what the issue is with it. Is there any other option?Robert Levonyan
04/18/2025, 11:25 AMisSystemInDarkTheme()
is checking for the device dark mode. If you change it manually and don't follow the system theme, you should set it manually with AppCompatDelegateHayk
04/18/2025, 12:17 PMAppCompatDelegate
breaks my app UI, the system bars get black. My guess is that there may be some composable state issues because of the configuration change. But it happens only on emulators with android 15. Tried with 2-3 real devices, works fine.
The fix for now is to use UiModeManager
for android 12 and above.mattinger
04/18/2025, 2:47 PMComponentActivity.enableEdgeToEdge
function has an auto setting that pays attention to the system mode to set your status bars to either dark or light colors. On android 15, this is automatically triggered. On all versions below android 15, you have to do this yourself.
I would recommend you update all your activities to call this function in the onCreate, before you set any view content (xml or compose) so that you get the same behavior on all versions of android.
And if you have application specific logic as to whether or not are in dark or light mode, you can pass that to the function as well.
internal fun Context.getComponentActivity(): ComponentActivity? = when (this) {
is ComponentActivity -> this
is ContextWrapper -> baseContext.getComponentActivity()
else -> null
}
@Composable
fun EdgeToEdgeSideEffect(
isStatusBarLight: Boolean,
isNavigationBarLight: Boolean
) {
val activity = LocalContext.current.getComponentActivity()
activity?.let {
DisposableEffect(
isStatusBarLight, isNavigationBarLight
) {
activity.enableEdgeToEdge(
statusBarStyle =
if (isStatusBarLight) {
SystemBarStyle.light(
Color.TRANSPARENT,
Color.TRANSPARENT
)
} else {
SystemBarStyle.dark(
Color.TRANSPARENT
)
},
navigationBarStyle =
if (isNavigationBarLight) {
SystemBarStyle.light(
Color.TRANSPARENT,
Color.TRANSPARENT
)
} else {
SystemBarStyle.dark(
Color.TRANSPARENT
)
}
)
onDispose { }
}
}
}
Hayk
04/18/2025, 6:12 PMsetContent
before I create my other composables? Though does it make sense, cause it's in a DisposableEffect?mattinger
04/18/2025, 6:18 PMmattinger
04/18/2025, 6:18 PMHayk
04/18/2025, 6:25 PMDisposableEffect(systemBarColors, isInDarkMode) {
with(WindowCompat.getInsetsController(window, window.decorView)) {
isAppearanceLightStatusBars = systemBarColors.statusBarDarkIcons
isAppearanceLightNavigationBars = systemBarColors.navigationBarDarkIcons
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
window.navigationBarColor = systemBarColors.navigationBarColor.toArgb()
}
onDispose { }
}
Actually I don't think it's connected with edgeToEdge, though it only happens on Android 15. Below that works fine.
I tried using your way, but it didn't work 🥲Hayk
04/18/2025, 6:27 PMHayk
04/18/2025, 6:28 PMmattinger
04/18/2025, 6:29 PMmattinger
04/18/2025, 6:29 PMHayk
04/18/2025, 6:30 PMHayk
04/18/2025, 6:31 PMmattinger
04/18/2025, 6:32 PMmattinger
04/18/2025, 6:33 PMSurface(
color = statusBarColor,
modifier = Modifier
.fillMaxSize()
) {
Box(
modifier = Modifier
.fillMaxSize()
.statusBarsPadding()
.displayCutoutPadding()
.background(backgroundColor)
.navigationBarsPadding()
) {
content()
}
}
mattinger
04/18/2025, 6:34 PMmattinger
04/18/2025, 6:35 PMHayk
04/18/2025, 6:36 PMHayk
04/18/2025, 6:37 PMContext.getComponentActivity
as they already have LocalActivity.current
mattinger
04/18/2025, 6:38 PM