【问题标题】:Jetpack Compose Scaffold + Modal Bottom SheetJetpack Compose 脚手架 + 模态底板
【发布时间】:2021-05-28 19:13:01
【问题描述】:

我正在尝试使用 Compose 设计一个布局,其中包括:

  1. TopAppBar
  2. 正文(内容)
  3. BottomAppBar
  4. 单击时表示菜单的底部表(模态底部表)

-------TopAppBar-------

-----MainContent------

------BottomAppBar-----

----ModalBottomSheet---

Compose 提供 3 个组件:

  1. 脚手架
  2. 底页脚手架
  3. ModalBottomSheetLayout

脚手架没有底页属性

BottomSheetScaffold 没有 BottomAppBar 属性

ModalBottomSheetLayout只有 content 和 sheetContent

Which of these components should I combine and in what **structure** to achieve what I want?

Scaffold(
  topBar = { TopBar() },
  content = { innerPadding -> Body(innerPadding) },
  bottomAppbar = { BottomAppBar() }
)
ModalBottomSheetLayout(
  sheetState = rememberModalBottomSheetState(
    initialValue = ModalBottomSheetValue.Hidden
  ),
  sheetContent = { SheetContent() },
)
BottomSheetScaffold(
  scaffoldState = ...,
  sheetContent = { SheetContent() },
  content = { ScreenContent() },
)

【问题讨论】:

    标签: android android-jetpack-compose


    【解决方案1】:

    你可以使用类似的东西:

    val bottomState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
    ModalBottomSheetLayout(
        sheetState = bottomState,
        sheetContent = {
            //. sheetContent
        }
    ) {
        Scaffold(
            scaffoldState = scaffoldState,
            topBar = {
                TopAppBar(
                    title = {
                        Text(text = "TopAppBar")
                    }
                )
            },
            bottomBar = {
                BottomAppBar(modifier = Modifier) {
                    IconButton(
                        onClick = {
                            coroutineScope.launch { bottomState.show() }  
                        }
                    ) {
                        Icon(Icons.Filled.Menu, contentDescription = "Localized description")
                    }
                }
            },
    
            content = { innerPadding ->
                //...main content
            }
        )
    }
    

    【讨论】:

      猜你喜欢
      • 2021-10-05
      • 2021-11-11
      • 2021-05-27
      • 2022-06-15
      • 2023-01-05
      • 1970-01-01
      • 1970-01-01
      • 2022-11-13
      • 1970-01-01
      相关资源
      最近更新 更多