我希望在Jetpack Compose中实现透明状态栏。
我已经集成了Accompanist库,但它对状态栏没有透明效果。
implementation "com.google.accompanist:accompanist-systemuicontroller:0.18.0"
// Remember a SystemUiController
val systemUiController = rememberSystemUiController()
val useDarkIcons = !isSystemInDarkTheme()
DisposableEffect(systemUiController, useDarkIcons) {
// Update all of the system bar colors to be transparent, and use
// dark icons if we're in light theme
systemUiController.setStatusBarColor(
color = Color.Transparent,
darkIcons = useDarkIcons
)
// setStatusBarColor() and setNavigationBarColor() also exist
onDispose {}
}
我也尝试了这个方法,但是它在手势导航方面存在问题。
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
val insets = WindowCompat.getInsetsController(window, view)
window.statusBarColor = Color.Transparent.toArgb() // choose a status bar color
window.navigationBarColor = Color.Transparent.toArgb() // choose a navigation bar color
insets.isAppearanceLightStatusBars = !useDarkTheme
insets.isAppearanceLightNavigationBars = !useDarkTheme
}
}
请提供更好的透明状态栏解决方案。
![enter image description here](https://istack.dev59.com/cMfuT.webp)
WindowCompat.setDecorFitsSystemWindows(window, false)
? - Gabriele Mariottiandroidx.activity:activity:1.8.0
,并使用enableEdgeToEdge()
功能,非常简单且可定制化。 - undefined