本文主要是介绍Android Compose Material3 ModalNavigationDrawer 抽屉的使用(处理了一些坑),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Android Compose Material3 ModalNavigationDrawer 抽屉的使用(处理了一些坑)
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
val scope = rememberCoroutineScope()ModalNavigationDrawer(drawerState = drawerState,drawerContent = {// 处理 Back 事件BackHandler(drawerState.isOpen) {scope.launch { drawerState.close() }}// requiredWidth 重置抽屉宽度为指定值,但是不能过大ModalDrawerSheet(modifier = Modifier.requiredWidth(320.dp)) {// 抽屉内容}},// 仅在抽屉打开时允许手势开关抽屉,防止手势冲突gesturesEnabled = drawerState.isOpen
) {Scaffold(modifier = Modifier.fillMaxSize(),topBar = {TopAppBar(navigationIcon = {// 打开抽屉的按钮IconButton(onClick = {scope.launch { drawerState.open() }}) {Icon(imageVector = Icons.Default.Menu, contentDescription = "打开抽屉")}})}){// 页面内容}
}
这篇关于Android Compose Material3 ModalNavigationDrawer 抽屉的使用(处理了一些坑)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!