我正在尝试使浮动操作按钮向上移动以为 Snackbar 出现腾出空间,这是使用 android xml UI 文件时的正常行为。
看起来它没有在 Scafford 中实现。
到目前为止,请在 Compose for desktop 上找到我的代码(但在 Android 上应该类似):
fun main() = Window(
title = "Box Demo",
size = IntSize(600, 500)
) {
MaterialTheme {
val snackbarHostState = remember { SnackbarHostState() }
val scaffoldState = rememberScaffoldState()
Scaffold(
scaffoldState = scaffoldState,
snackbarHost = {scaffoldState.snackbarHostState },
floatingActionButtonPosition = FabPosition.End,
floatingActionButton = { FloatingActionButton(onClick = {}) { Text("+") } },
topBar = { TopAppBar(title = { Text("TopAppBar") }) },
bottomBar = { BottomAppBar() { Text("BottomAppBar") } }
) {
Column(
modifier = Modifier.fillMaxSize()
) {
Button(
modifier = Modifier.padding(top = 20.dp, start = 20.dp),
onClick = {
GlobalScope.launch {
snackbarHostState.showSnackbar(
message = "Hey I am a snackbar",
actionLabel = "Hide",
duration = SnackbarDuration.Short
)
}
}
) {
Text("Show snackbar")
}
SnackbarHost(
modifier = Modifier.padding(top = 180.dp),
hostState = snackbarHostState,
snackbar = {
Snackbar(
action = {
TextButton(
onClick = {
snackbarHostState.currentSnackbarData?.dismiss()
}
) {
Text(
text = snackbarHostState.currentSnackbarData?.actionLabel ?: "",
style = TextStyle(color = Color.White)
)
}
}
) {
Text(snackbarHostState.currentSnackbarData?.message ?: "")
}
}
)
}
}
}
}
我的配置:
plugins {
kotlin("jvm") version "1.4.21"
id("org.jetbrains.compose") version "0.2.0-build132"
}