我怎样才能得到这个标杆的高度?现在不再推荐伴奏,WindowInsets.systemBars.asPaddingValues()每次给我0.Modifier.statusBarsPadding()在我的布局中什么也不做。有办法达到这个高度吗?!?
发布于 2022-08-23 08:41:44
当我在活动的WindowCompat.setDecorFitsSystemWindows(window, false)之前调用setContent时,我得到正确的值,否则它返回0。
@Composable
private fun MyComposable() {
Column {
val paddingValues = WindowInsets.systemBars.asPaddingValues()
Spacer(modifier=Modifier.height(paddingValues.calculateTopPadding()))
Text(text = "Padding values: $paddingValues")
}
}结果

无WindowCompat.setDecorFitsSystemWindows(window, false)

发布于 2022-08-23 08:29:18
您应该能够使用以下方法获得statusbar的高度:
val statusBarHeight = WindowInsets.statusBars.asPaddingValues().calculateTopPadding()如果要将高度用作修饰符:(来自伴奏迁移表:https://google.github.io/accompanist/insets/#migration-table)
Modifier.windowInsetsTopHeight(WindowInsets.statusBars)https://stackoverflow.com/questions/73455192
复制相似问题