[英]Modal Bottom Sheet scrim color is not shown in status bar in Jetpack compose
将视图系统中的应用程序迁移到 Jetpack Compose。
底部床单稀松布颜色显示在当前应用程序的状态栏上。
如何在 Jetpack Compose 中重现相同内容?
使用视图的应用程序屏幕截图
使用 compose 的应用程序屏幕截图
编写代码
val modalBottomSheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
)
val coroutineScope = rememberCoroutineScope()
ModalBottomSheetLayout(
sheetState = modalBottomSheetState,
sheetContent = {
// Not relevant
},
) {
Scaffold(
scaffoldState = scaffoldState,
topBar = {
// Not relevant
},
floatingActionButton = {
FloatingActionButton(
onClick = {
coroutineScope.launch {
if (!modalBottomSheetState.isAnimationRunning) {
if (modalBottomSheetState.isVisible) {
modalBottomSheetState.hide()
} else {
modalBottomSheetState.show()
}
}
}
},
) {
Icon(
imageVector = Icons.Rounded.Add,
contentDescription = "Add",
)
}
},
modifier = Modifier
.fillMaxSize(),
) { innerPadding ->
// Not relevant - Nav graph code
}
}
尝试使用伴奏库中的System UI Controller来控制 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
}
在最新版本的 Compose 中,默认情况下在Theme.kt
文件中设置了一个statusBarColor
参数。 如果您不使用伴奏,请尝试更改该值以获得所需的效果。
您可以删除自动昆虫并使状态栏透明:
WindowCompat.setDecorFitsSystemWindows(window, false)
window.statusBarColor = android.graphics.Color.TRANSPARENT;
然后绘制你的底片,它会在所有系统栏包括状态栏下显示 go
只是不要忘记在需要时为视图的 rest 添加昆虫,它现在在 compose foundation 中:
modifier = Modifier
.navigationBarsPadding()
.captionBarPadding()
.imePadding()
.statusBarsPadding(),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.