android-studio - 如何更改 FAB 上的图标并将项目重新定位到 Jetpack Compose 的末尾/右侧?

标签 android-studio android-jetpack-compose

BottomBar
因此,我尝试制作一个 BottomNavBar 并使用它,但是当我在 FloatingActionButton 上使用 Icon 属性时,它没有注册,而且我想重新定位底部导航上的所有项目以进行练习,但无法弄清楚

bottomBar = {
                    BottomAppBar(backgroundColor = materialBlue700, cutoutShape = CircleShape) {
                        Text(text = "BottomAppBar")
                        Button(
                                onClick = { },
                        backgroundColor = Color.Yellow) {
                        Row {
                            Spacer(Modifier.preferredSize(4.dp).padding(32.dp))
                            Text("Button")
                        }
                    }
                        IconButton(onClick = {
                            scaffoldState.drawerState.open()
                        }) {
                            Icon(Icons.Filled.Menu)
                        }
                        Spacer(modifier = Modifier.weight(1f, true))

           

 }
        },
        floatingActionButtonPosition = FabPosition.End,
        isFloatingActionButtonDocked = true,
        floatingActionButton = {
            FloatingActionButton(
                    shape = CircleShape,
                    onClick = {},
            ) {
                Icon(asset = Icons.Filled.Add)
            }
        }

编辑:“它不注册”是指该卡未显示在预览中

最佳答案

在内部,BottomAppBar 用户使用 Row 来对齐组件(与水平方向的 LinearLayout 相同),因此您需要相应地添加项目.

例如:

@Composable
fun BottomBarSample() {
    Scaffold(
        drawerContent = { },
        topBar = { },
        floatingActionButton = {
            FloatingActionButton(
                shape = CircleShape,
                onClick = {},
            ) {
                Icon(asset = Icons.Filled.Add)
            }
        },
        floatingActionButtonPosition = FabPosition.End,
        isFloatingActionButtonDocked = true,
        bodyContent = { },
        bottomBar = {
            BottomAppBar(backgroundColor = purple500, cutoutShape = CircleShape) {
                IconButton(onClick = {
//                    scaffoldState.drawerState.open()
                }) {
                    Icon(Icons.Filled.Menu, tint = Color.Red)
                }

                Text(text = "BottomAppBar")

                Spacer(modifier = Modifier.preferredSize(16.dp))

                Button(
                    onClick = { },
                    backgroundColor = Color.Red
                ) {
                    Row() {
                        Text("Button")
                    }
                }
            }
        }
    )
} 

预览将如下所示。 enter image description here

关于android-studio - 如何更改 FAB 上的图标并将项目重新定位到 Jetpack Compose 的末尾/右侧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64379500/

相关文章:

android - App Bundles (AAB) 是否自动使用 APK 签名方案 v2?

android - 当我重新启动动画时,如何重置 JetpackCompose AnimatedFloat 的初始值?

android - (撰写 UI)- 键盘 (IME) 与应用程序的内容重叠

android - TopAppBar 与 Navigation 集成的脚手架

android - Jetpack Compose 中列和行的 Expanded 和 LayoutSize.Expand 的区别

android-studio - 安卓工作室 : Unable to add a new class or any file to a project

java - 用于 Espresso 测试的 Android Studio 项目设置

android - 如何更改 Android Studio 3.0.1 中新项目的默认文件结构?

android - build.gradle 和 Manifest 文件丢失了吗?

android - 喷气背包中 +(...)% 颜色的表面组成