底部弹窗ModalBottomSheetLayout
ModalBottomSheetLayout 是 Jetpack Compose 中的一个组件,用于创建底部弹窗。它可以在屏幕底部显示一个半透明的背景,并从底部滑出一个内容面板。ModalBottomSheetLayout 包含两个主要部分:背景和内容面板。
效果图:
代码如下:
val modalBottomSheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden )val coroutineScope =rememberCoroutineScope()Column {// 使用ModalBottomSheetLayout包装BottomSheet的内容ModalBottomSheetLayout(sheetState = modalBottomSheetState,sheetContent = {// BottomSheet的内容Column {Text("BottomSheet Content")Button(onClick = { coroutineScope.launch { modalBottomSheetState.hide() } }) {Text("Close BottomSheet")}}}) {// 主要内容Button(onClick = {Log.e("TAG","TTTTT")coroutineScope.launch { modalBottomSheetState.show() } }) {Text("弹出 BottomSheet")}}}