首页 > 解决方案 > 使用 ModalBottomSheetLayout 时,如何在 Jetpack compose 中使背景和状态栏透明

问题描述

我是喷气背包的新手。我的应用在 MainScreen 中有 ModalBottomSheetLayout。现在,当我单击 MainScreen 的按钮时,它会显示 BottomSheet。当底部工作表打开时,背景是透明的,但状态栏不是。如何让它透明?

标签: android-jetpack-composebottom-sheetandroid-statusbar

解决方案


至此,可以使用System UI Controller中的accompanist library来控制 statusBar Color 和 navigationBar 颜色

implementation "com.google.accompanist:accompanist-systemuicontroller:0.18.0"
// Remember a SystemUiController
val systemUiController = rememberSystemUiController()
val useDarkIcons = MaterialTheme.colors.isLight

SideEffect {
    // Update all of the system bar colors to be transparent, and use
    // dark icons if we're in light theme
    systemUiController.setSystemBarsColor(
        color = Color.Transparent,
        darkIcons = useDarkIcons
    )

    // setStatusBarsColor() and setNavigationBarsColor() also exist
}

推荐阅读