gpt4 book ai didi

android - jetpack compose 中的 fitSystemWindows 对应项

转载 作者:行者123 更新时间:2023-12-04 13:30:42 28 4
gpt4 key购买 nike

我有一个透明的状态/导航栏,当我使用默认布局(顶部/左侧)放置一个撰写元素时,它被放置在状态栏下方。在 xml 中我使用 fitsSystemWindows要解决这个问题,我怎样才能在 jetpack compose 中获得相同的效果?

最佳答案

这对我有用,在 Activity 中我有:

  WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
JetpackComposePlaygroundTheme {
val controller = rememberAndroidSystemUiController()
CompositionLocalProvider(LocalSystemUiController provides controller) {
ProvideWindowInsets {
ComposeAppPlayground()
}
}
}
}
然后在撰写应用程序游乐场我有这样的事情:
  Surface {

var topAppBarSize by remember { mutableStateOf(0) }
val contentPaddings = LocalWindowInsets.current.systemBars.toPaddingValues(
top = false,
additionalTop = with(LocalDensity.current) { topAppBarSize.toDp() }
)

Column(modifier = Modifier.navigationBarsPadding().padding(top = contentPaddings.calculateTopPadding())) {
// content can go here forexample...
// if you want the content go below status bar
// you can remove the top padding for column
}

InsetAwareTopAppBar(
title = { Text(stringResource(R.string.home)) },
backgroundColor = MaterialTheme.colors.surface.copy(alpha = 0.9f),
modifier = Modifier
.fillMaxWidth()
.onSizeChanged { topAppBarSize = it.height }
)
}
}
还有我从 https://google.github.io/accompanist/insets/ 中提到的 guid 中找到的 InsetAwareTopAppBar
@Composable
fun InsetAwareTopAppBar(
title: @Composable () -> Unit,
modifier: Modifier = Modifier,
navigationIcon: @Composable (() -> Unit)? = null,
actions: @Composable RowScope.() -> Unit = {},
backgroundColor: Color = MaterialTheme.colors.primarySurface,
contentColor: Color = contentColorFor(backgroundColor),
elevation: Dp = 4.dp
) {
Surface(
color = backgroundColor,
elevation = elevation,
modifier = modifier
) {
TopAppBar(
title = title,
navigationIcon = navigationIcon,
actions = actions,
backgroundColor = Color.Transparent,
contentColor = contentColor,
elevation = 0.dp,
modifier = Modifier
.statusBarsPadding()
.navigationBarsPadding(bottom = false)
)
}
}


关于android - jetpack compose 中的 fitSystemWindows 对应项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65260293/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com