gpt4 book ai didi

android - Jetpack UI 组合。如何创建 FloatingActionButton?

转载 作者:行者123 更新时间:2023-12-04 23:11:58 25 4
gpt4 key购买 nike

我想创建一个 FloatingActionButton使用 jetpack compose 放置在 Activity 的右下角.
任何人都可以帮我举一个上述场景的例子吗?

最佳答案

1.0.x创建 FloatingActionButton ExtendedFloatingActionButton 你可以使用类似的东西:

val onClick = { /* Do something */ }

//Simple FAB
FloatingActionButton(onClick = onClick) {
Icon(Icons.Filled.Add,"")
}

//FAB custom color
FloatingActionButton(
onClick = onClick,
backgroundColor = Color.Blue,
contentColor = Color.White
){
Icon(Icons.Filled.Add,"")
}

//Square FAB
FloatingActionButton(
onClick = onClick,
shape = RectangleShape
){
Icon(Icons.Filled.Add,"")
}

//EXTENDED FAB
ExtendedFloatingActionButton(
text = { Text(text = "EXTENDED FAB") },
onClick = onClick,
icon ={ Icon(Icons.Filled.Add,"")}
)

//EXTENDED FAB WITHOUT ICON
ExtendedFloatingActionButton(
text = {
Text(text = "EXTENDED FAB")
},
onClick = onClick
)
enter image description here
例子:
Scaffold(topBar = { } ,
//floatingActionButtonPosition = FabPosition.End,
floatingActionButton = {
FloatingActionButton(
onClick = {}
) {
Icon(Icons.Filled.Add,"")
}
}
, content = {
//....
})
enter image description here

关于android - Jetpack UI 组合。如何创建 FloatingActionButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58547448/

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