底部动作条

如果您要实现底部动作条,可以使用 ModalBottomSheet 可组合项。

您可以使用 content 槽,该槽使用 ColumnScope 将工作表内容可组合项的布局设为一列:

ModalBottomSheet(onDismissRequest = { /* Executed when the sheet is dismissed */ }) {
    // Sheet content
}

您可以使用 SheetState 以程序化方式展开和收起工作表。您可以使用 rememberSheetState 创建一个 SheetState 实例,该实例应通过 sheetState 参数传递给 ModalBottomSheetSheetState 可用于访问 showhide 函数,以及与当前工作表状态相关的属性。这些挂起函数需要 CoroutineScope(例如,使用 rememberCoroutineScope),并且可被调用以响应界面事件。请务必在隐藏底部动作条时从组合中移除 ModalBottomSheet

val sheetState = rememberModalBottomSheetState()
val scope = rememberCoroutineScope()
var showBottomSheet by remember { mutableStateOf(false) }
Scaffold(
    floatingActionButton = {
        ExtendedFloatingActionButton(
            text = { Text("Show bottom sheet") },
            icon = { Icon(Icons.Filled.Add, contentDescription = "") },
            onClick = {
                showBottomSheet = true
            }
        )
    }
) { contentPadding ->
    // Screen content

    if (showBottomSheet) {
        ModalBottomSheet(
            onDismissRequest = {
                showBottomSheet = false
            },
            sheetState = sheetState
        ) {
            // Sheet content
            Button(onClick = {
                scope.launch { sheetState.hide() }.invokeOnCompletion {
                    if (!sheetState.isVisible) {
                        showBottomSheet = false
                    }
                }
            }) {
                Text("Hide bottom sheet")
            }
        }
    }
}