北京教育学会网站建设微信开发者账号

张小明 2026/1/19 17:31:14
北京教育学会网站建设,微信开发者账号,天元建设集团有限公司第六建筑工程公司,外贸响应式网站建设这一节主要了解一下Compose中的ModalNavigationDrawer,在Jetpack Compose开发中#xff0c;ModalNavigationDrawer是一个用于实现模态导航抽屉的核心组件#xff0c;它允许用户通过侧滑手势或点击菜单图标触发一个覆盖在主内容之上的抽屉菜单#xff0c;提供页面切换、功能导…这一节主要了解一下Compose中的ModalNavigationDrawer,在Jetpack Compose开发中ModalNavigationDrawer是一个用于实现模态导航抽屉的核心组件它允许用户通过侧滑手势或点击菜单图标触发一个覆盖在主内容之上的抽屉菜单提供页面切换、功能导航等功能。简单总结如下:API:drawerContent定义抽屉菜单的内容。drawerState控制抽屉的打开/关闭状态。gesturesEnabled是否启用侧滑手势。scrimColor抽屉背景的遮罩层颜色。content抽屉外部的主内容。一般场景:1 页面导航 通过抽屉菜单切换不同页面2 功能入口 集中管理应用的核心功能3 账号管理 提供快速访问账号设置、个人资料的入口栗子:import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Home import androidx.compose.material.icons.outlined.Menu import androidx.compose.material.icons.outlined.Message import androidx.compose.material.icons.outlined.Person import androidx.compose.material.icons.outlined.Settings import androidx.compose.material3.DrawerValue import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.ModalDrawerSheet import androidx.compose.material3.ModalNavigationDrawer import androidx.compose.material3.NavigationDrawerItem import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.material3.rememberDrawerState import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import kotlinx.coroutines.launch OptIn(ExperimentalMaterial3Api::class) Composable fun ModalNavigationDrawerDemo() { val coroutineScope rememberCoroutineScope() val drawerState rememberDrawerState(initialValue DrawerValue.Closed) data class NavItem( val title: String, val icon: Composable () - Unit ) val navItems remember { listOf( NavItem(首页, { Icon(Icons.Outlined.Home, contentDescription null) }), NavItem(消息, { Icon(Icons.Outlined.Message, contentDescription null) }), NavItem(我的, { Icon(Icons.Outlined.Person, contentDescription null) }), NavItem(设置, { Icon(Icons.Outlined.Settings, contentDescription null) }) ) } val selectedItemIndex remember { mutableStateOf(0) } ModalNavigationDrawer( drawerState drawerState, drawerContent { ModalDrawerSheet { LazyColumn( modifier Modifier.padding(16.dp), verticalArrangement Arrangement.spacedBy(8.dp) ) { items(navItems.size) { index - val item navItems[index] NavigationDrawerItem( label { Text(text item.title) }, selected selectedItemIndex.value index, onClick { selectedItemIndex.value index coroutineScope.launch { drawerState.close() } }, icon item.icon, modifier Modifier.padding(horizontal 8.dp) ) } } } }, content { Scaffold( topBar { TopAppBar( title { Text(text navItems[selectedItemIndex.value].title) }, navigationIcon { IconButton( onClick { coroutineScope.launch { drawerState.open() } } ) { Icon(Icons.Outlined.Menu, contentDescription 打开抽屉) } } ) } ) { innerPadding - Column( modifier Modifier .fillMaxSize() .padding(innerPadding) .padding(32.dp), horizontalAlignment Alignment.CenterHorizontally, verticalArrangement Arrangement.Center ) { Text( text 当前页面${navItems[selectedItemIndex.value].title}, style MaterialTheme.typography.headlineSmall ) Text( text 可通过左侧手势滑动打开抽屉, style MaterialTheme.typography.bodyMedium, modifier Modifier.padding(top 16.dp) ) } } } ) }import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Home import androidx.compose.material.icons.outlined.Menu import androidx.compose.material.icons.outlined.Message import androidx.compose.material.icons.outlined.Person import androidx.compose.material3.Badge import androidx.compose.material3.DrawerValue import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.ModalDrawerSheet import androidx.compose.material3.ModalNavigationDrawer import androidx.compose.material3.NavigationDrawerItem import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.material3.rememberDrawerState import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import kotlinx.coroutines.launch OptIn(ExperimentalMaterial3Api::class) Composable fun ModalNavigationDrawerDemo() { val coroutineScope rememberCoroutineScope() val drawerState rememberDrawerState(initialValue DrawerValue.Closed) data class NavItem( val title: String, val icon: Composable () - Unit, val badgeCount: Int? null ) val navItems remember { listOf( NavItem(首页, { Icon(Icons.Outlined.Home, contentDescription null) }), NavItem(消息, { Icon(Icons.Outlined.Message, contentDescription null) }, 99), // 带99条未读消息 NavItem(我的, { Icon(Icons.Outlined.Person, contentDescription null) }) ) } val selectedItemIndex remember { mutableStateOf(0) } ModalNavigationDrawer( drawerState drawerState, drawerContent { ModalDrawerSheet( modifier Modifier.width(280.dp) ) { LazyColumn( modifier Modifier .fillMaxWidth() .padding(16.dp), verticalArrangement Arrangement.spacedBy(12.dp) ) { item { Text( text 我的导航, style MaterialTheme.typography.titleLarge, modifier Modifier.padding(horizontal 8.dp, vertical 16.dp) ) } items(navItems.size) { index - val item navItems[index] NavigationDrawerItem( label { Text(text item.title) }, selected selectedItemIndex.value index, onClick { selectedItemIndex.value index coroutineScope.launch { drawerState.close() } }, icon item.icon, badge item.badgeCount?.let { count - { Badge { Text(text count.toString(), fontSize 12.sp) } } }, modifier Modifier.padding(horizontal 8.dp) ) } } } }, scrimColor Color.Gray.copy(alpha 0.5f), gesturesEnabled false, content { Scaffold( topBar { TopAppBar( title { Text(text navItems[selectedItemIndex.value].title) }, navigationIcon { IconButton( onClick { coroutineScope.launch { if (drawerState.isOpen) { drawerState.close() } else { drawerState.open() } } } ) { Icon(Icons.Outlined.Menu, contentDescription 切换抽屉) } } ) } ) { innerPadding - Column( modifier Modifier .fillMaxSize() .padding(innerPadding) .padding(32.dp), horizontalAlignment Alignment.CenterHorizontally, verticalArrangement Arrangement.Center ) { Text( text 自定义抽屉样式Demo, style MaterialTheme.typography.headlineSmall ) Text( text 1. 自定义遮罩颜色\n2. 消息项带99条未读徽章\n3. 禁用手势滑动 \n4. 自定义抽屉宽度, style MaterialTheme.typography.bodyMedium, modifier Modifier.padding(top 16.dp), ) } } } ) }注意:1 避免在drawerContent中使用复杂布局或高频更新的组件可能导致卡顿。2 drawerState.open()和drawerState.close()是挂起函数必须在协程作用域。3 ModalNavigationDrawer需要Compose Material 3支持。
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

做网站建设怎么样域名备案网站备案查询

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容: 开发一个Maven项目配置检查器,专门针对企业级项目常见的部署问题。当检测到repository element was not specified错误时,不仅能指出问题所在,还…

张小明 2026/1/17 15:28:54 网站建设

永州网站推广做网站首次备案需要哪些资料

PyTorch镜像中实现对比学习损失函数InfoNCE 在当前自监督学习迅猛发展的背景下,对比学习已成为无标签数据表示学习的核心范式。其中,InfoNCE 损失函数作为 SimCLR、MoCo 等经典框架的“引擎”,其高效实现直接决定了模型训练的速度与稳定性。然…

张小明 2026/1/17 15:28:53 网站建设

迁西县住房和城乡规划建设局网站营销系统四大系统

GLM-TTS能否生成童声?不同年龄音色模拟效果对比 在智能语音助手越来越“懂人心”的今天,我们早已不满足于机械朗读式的合成语音。从儿童绘本的温柔讲解,到动画角色的生动演绎,用户期待的是有温度、有性格、甚至能分辨出“这是个小…

张小明 2026/1/17 15:28:52 网站建设

网站编程器企业网站优化

实战指南:5步构建可扩展的AI助手管理系统 【免费下载链接】personal-ai 项目地址: https://gitcode.com/GitHub_Trending/pe/personal-ai 你是否在为如何高效管理多个AI助手实例而苦恼?GitHub_Trending/pe/personal-ai项目展示了一个实用的AI助手…

张小明 2026/1/17 13:09:04 网站建设

网站建设合同需要印花税深圳的外贸公司有哪些

无线电能传输仿真模型,电路采用S-S拓扑结构。 闭环输出电压400v,输出效果良好。 采用的是移相控制。 另有主电路的参数设计过程。深夜两点盯着示波器屏幕,突然发现谐振电流的波形开始优雅地跳起华尔兹——这是我在调试S-S型无线电能传输系统时…

张小明 2026/1/17 15:28:51 网站建设

万盛集团网站建设网站静态与动态

如果你也是从 public static void main(String[] args) 和 System.out.println() 开始Java生涯的,那也是Java老油条了。在日常的业务开发中,我们每天都在写着增删改查的逻辑,有时候会觉得Java有点笨重,语法有点啰嗦。 但其实&…

张小明 2026/1/17 15:28:54 网站建设