Colton Idle
11/07/2023, 2:11 PMeygraber
11/07/2023, 3:25 PMactivity.enableEdgeToEdge
from the androidx activity library and that covered my use cases for drawing under the status and nav bars + coloring themStylianos Gakis
11/07/2023, 3:25 PMenableEdgeToEdge
not fill your requirements here?Albert Chang
11/07/2023, 3:40 PMval windowInsetsController: WindowInsetsControllerCompat?
@Composable get() {
val view = LocalView.current
return remember(view) {
view.context.findWindow()?.let { WindowCompat.getInsetsController(it, view) }
}
}
private tailrec fun Context.findWindow(): Window? =
when (this) {
is Activity -> window
is ContextWrapper -> baseContext.findWindow()
else -> null
}
And use it like this:
val controller = windowInsetsController
SideEffect {
controller?.isAppearanceLightStatusBars = !darkTheme
}
Francesc
11/07/2023, 4:15 PMColton Idle
11/07/2023, 6:06 PMColton Idle
11/07/2023, 6:07 PMAlbert Chang
11/08/2023, 1:24 AMenableEdgeToEdge
can only help you set up edge to edge, and you still need to change status bar appearance yourself if you are disabling activity recreation.Colton Idle
11/08/2023, 1:29 AMAlbert Chang
11/08/2023, 1:32 AMuiMode
in android:configChanges
, the activity won’t be recreated when dark mode changes, and status bar icon color won’t change automatically.Francesc
11/08/2023, 1:37 AMDisposableEffect(darkTheme) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(
android.graphics.Color.TRANSPARENT,
android.graphics.Color.TRANSPARENT,
) { darkTheme },
navigationBarStyle = SystemBarStyle.auto(
lightScrim,
darkScrim,
) { darkTheme },
)
onDispose {}
}
https://github.com/android/nowinandroid/blob/5f5bd91a686a414007c9ce3c7acb26d2b0bd2[…]ain/kotlin/com/google/samples/apps/nowinandroid/MainActivity.ktAlbert Chang
11/08/2023, 1:42 AMfindWindow
part is not needed if you put it in an activity class like NIA does).Colton Idle
11/08/2023, 7:29 AMColton Idle
11/08/2023, 7:30 AM