我正在使用Android应用程序中的jectpack compose
。所以我想使用use bottomAppbar
。从来没有发现任何例子可以有人帮助吗?
答案 0 :(得分:5)
通过1.0.0-alpha01
,您可以使用BottomAppBar
BottomAppBar (backgroundColor = yellow500) {
IconButton(onClick = { /* doSomething() */ }) {
Icon(Icons.Filled.Menu)
}
// The actions should be at the end of the BottomAppBar
Spacer(Modifier.weight(1f, true))
IconButton(onClick = { /* doSomething() */ }) {
Icon(Icons.Filled.Favorite)
}
IconButton(onClick = { /* doSomething() */ }) {
Icon(Icons.Filled.Call)
}
}
使用FAB:
val fabShape = CircleShape
val scaffoldState = rememberScaffoldState()
Scaffold(topBar = { },
bottomBar = {
BottomAppBar(cutoutShape = fabShape) {
IconButton(onClick = {
scaffoldState.drawerState.open()
}) {
Icon(Icons.Filled.Menu)
}
}
},
floatingActionButtonPosition = FabPosition.Center,
isFloatingActionButtonDocked = true,
floatingActionButton = {
FloatingActionButton(
shape = fabShape,
onClick = {}
) {
Icon(asset = Icons.Filled.Add)
}
}, bodyContent = {
//bodyContent()
})
答案 1 :(得分:4)
是的jetpack compose
通过简单的BottomAppBar
支持FloatingActionButton
查看下面的代码示例,它可以为您提供更多帮助
BottomAppBarWithoutFab
@Composable
fun BottomAppBarNoFab(getMyActionImage: () -> Image, getMyNavigationImage: () -> Image) {
val someActionImage: Image = getMyActionImage()
val someNavigationImage: Image = getMyNavigationImage()
val navigationIcon: @Composable() () -> Unit = {
AppBarIcon(someNavigationImage) { /* doSomething()*/ }
}
val actionData = listOf(someActionImage)
BottomAppBar(
navigationIcon = navigationIcon,
actionData = actionData
) { actionImage ->
AppBarIcon(actionImage) { /* doSomething()*/ }
}
}
检查BottomAppbarWithoutFab
屏幕截图
BottomAppBarWithCutout
@Composable
fun BottomAppBarCutoutFab(
getMyActionImage: () -> Image,
getMyNavigationImage: () -> Image
) {
val someActionImage: Image = getMyActionImage()
val someNavigationImage: Image = getMyNavigationImage()
val navigationIcon: @Composable() () -> Unit = {
AppBarIcon(someNavigationImage) { /* doSomething()*/}
}
val actionData = listOf(someActionImage)
BottomAppBar(
navigationIcon = navigationIcon,
fabConfiguration = BottomAppBar.FabConfiguration(cutoutShape = CircleShape) {
FloatingActionButton(
color = +themeColor { secondary },
icon = +imageResource(R.drawable.ic_add_icon),
onClick = { /** doSomething() */ })
},
actionData = actionData
) { actionImage ->
AppBarIcon(actionImage) { /* doSomething()*/ }
}
}
查看bottomAppbarcutoutFab
屏幕截图
检查以下代码,我们如何在@Compose
函数中调用
Column(mainAxisAlignment = MainAxisAlignment.End) {
BottomAppBarNoFab(getMyActionImage = {
+imageResource(R.drawable.ic_home_icon)
}, getMyNavigationImage = {
+imageResource(R.drawable.ic_heart_icon)
})
}