我想显示顶部栏下方但底部栏上方的NavigationDrawer.

以下是我到目前为止实现的内容.目前,它显示在顶栏下方,也显示在底部栏下方.

enter image description here

@Composable
fun MainScreen() {

    val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
    val scope = rememberCoroutineScope()


    Scaffold(
        topBar = {
            MyTopAppBar {
                scope.launch {
                    drawerState.open()
                }

            }
        },
        bottomBar = {


            MyBottomAppBar(modifier = Modifier.height(65.dp)) {
                val modifier = Modifier
                    .weight(1f)
                    .fillMaxHeight();

                BottomAppBarItem(
                    "Calls",
                    Icons.Filled.Call,
                    false,
                    modifier
                )
                BottomAppBarItem(
                    "Search",
                    Icons.Filled.Search,
                    true,
                    modifier
                )
                BottomAppBarItem(
                    "Contacts",
                    Icons.Filled.AccountBox,
                    false,
                    modifier
                )

            }
        }


    ) { paddingValues ->



        // A surface container using the 'background' color from the theme
        Surface(
            modifier = Modifier
                .fillMaxSize()
                .padding(paddingValues),
            color = MaterialTheme.colorScheme.background
        ) {

            ModalNavigationDrawer(gesturesEnabled = true, drawerContent = {

                DrawerContent()

            }, drawerState = drawerState) {


            }

        }

    }

}

推荐答案

我用它来显示底部导航上方的抽屉

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MainScreen() {
  val drawerState = rememberDrawerState(DrawerValue.Closed)
  val scope = rememberCoroutineScope()

  Column {
    TopAppBar(
        title = {
            Text(text = "Title")
        },
        navigationIcon = {
            IconButton(onClick = {
                if (drawerState.isClosed) {
                    scope.launch {
                        drawerState.open()
                    }
                } else {
                    scope.launch {
                        drawerState.close()
                    }
                }
            }) {
                Icon(imageVector = Icons.Default.List, contentDescription =null)
            }
        },
    )
    ModalNavigationDrawer(
        drawerState = drawerState,
        drawerContent = {
            // Drawer Items 
            Box(
                modifier = Modifier
                    .fillMaxHeight()
                    .background(Color.Blue),
            ) {
                Text(
                    "Settings",
                    style = MaterialTheme.typography.titleLarge
                )
            }
        },
        content = {
            Scaffold(
                bottomBar = {
                    NavigationBar {
                        // Bottom navigation items
                        NavigationBarItem(
                            selected = false,
                            icon = {
                                Icon(
                                    modifier = Modifier.size(32.dp),
                                    imageVector = Icons.Default.Favorite,
                                    contentDescription = null
                                )
                            },
                            onClick = {},
                        )
                    }
                },
                content = { paddingValues ->
                    Box(modifier = Modifier.padding(paddingValues))
                }
            )
        },
    )
 }
 }

Android相关问答推荐

打开平板电脑的下载文件夹中的文件,例如使用其mimeType将Intent发送到我们的应用程序

如何使TextField的背景透明?

在Android Studio Iguana上运行示例代码时,Gradle Build错误

Android Kotlin ImageView内置于Kotlin ImageView中.适配器未按预期更新

未解析的引用:视图模型

Android 访问任意公共目录

为什么@PrimaryKey val id: Int? = null 在创建 Room 实体时有效吗?

Material 3 中的 ModalBottomSheet 用于 compose

服务似乎在启动时忽略传递的变量

为卡片的上半部分添加一个边框,用圆角半径组合

AttributionSource 需要 android.permission.BLUETOOTH_SCAN 权限的问题

没有互联网连接时,Firebase Storage putFile() 永远不会完成

react 从输入中找到路径'lib/arm64-v8a/libfbjni.so'的本机2个文件

为什么我不能直接记住 mutableStateOf 可组合函数?

如何在 Dolphin 中启用 android studio new logcat | 2021.3.1 金丝雀 6?

Android Jetpack Compose - 每次文本字段值更改时,可组合函数都会重新组合

在android studio中使用wifi配对设备的问题

在 Kotlin 客户端应用程序中发送 FCM 推送通知 - Firebase 云消息传递

如何在 Jetpack Compose 中填充矢量图像的背景?

如何在android studio 2021.1中使用谷歌库以外的库