I've implemented the pinned
top app bar scroll container, and it works for changing the app bar color on scroll, however the status bar color isn't affected at all.
Here's what I have:
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
Scaffold(
Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
// just a wrapper for CenterAlignedTopAppBar
StandardTopAppBar("Home", scrollBehavior = scrollBehavior)
}
){ ... }
If it's relevant, in order to detect if the soft keyboard is present, I enabled:
WindowCompat.setDecorFitsSystemWindows(window, false)
And my status bar color in initially set in my Theme
. It was set to primary color when I autogenerated the project in android studios, but I changed it to surface color to match the appbar standards:
if (!view.isInEditMode) {
SideEffect {
(view.context as Activity).window.statusBarColor = colorScheme.surface.toArgb()
//(view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb()
ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = !darkTheme // changed from just darkTheme
}
}
tl;dr; top app bar color changes on scroll, but status bar does not. What is the correct pattern to use here? I looked through some of the pinnedScrollBehavior
code, and I don't see anything that would invoke status bar changes, so I'm wondering if I'm supposed to have the status bar be transparent and change the insets for the appbar? Or should I manually hook into the scroll logic and change the color myself? Any help is appreciated!