Compose - Scaffold使用

Compose - Scaffold使用

复制代码
/**
 * Author : wn
 * Email : maoning20080809@163.com
 * Date : 2026/1/1 19:32
 * Description : Scaffold组件提供了一个基本的APP结构,包括AppBar、底部导航栏和主要内容区域。通过声明式的方式,开发者可以轻松创建一致且可扩展的用户界面。
 */
class ScaffoldActivity : ComponentActivity(){

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            testScaffold()
        }
    }


    @OptIn(ExperimentalMaterial3Api::class)
    @SuppressLint("UnusedMaterialScaffoldPaddingParameter")
    @Preview
    @Composable
    fun testScaffold(){
        MaterialTheme{
            Scaffold(
                topBar = {
                    SmallTopAppBar(
                        title = {
                            Text(text = "我的TopBar")
                        },
                        actions = {
                            IconButton(onClick = {
                                println("点击1")
                            }) {
                                Icon(Icons.Default.AccountBox, contentDescription = null)
                            }
                        },
                        colors = TopAppBarDefaults.smallTopAppBarColors(
                            containerColor = MaterialTheme.colorScheme.primaryContainer,
                            titleContentColor = MaterialTheme.colorScheme.primary,
                        )
                    )
                },
                content = { innerPadding ->     // 接收 innerPadding 参数
                    Column(
                        modifier = Modifier.padding(innerPadding).fillMaxSize()
                    ) {
                        Text(
                            text = "Scaffold使用",
                            modifier = Modifier.padding(20.dp),
                            fontSize = 30.sp,
                            color = Color.Blue
                        )
                        Button(onClick = {
                            println("点击222")
                        },modifier = Modifier.padding(start = 20.dp)) {
                            Text(text = "Click Me", )
                        }
                    }
                },
                bottomBar = {
                    BottomAppBar() {
                        Row() {
                            IconButton(modifier = Modifier.weight(1f), onClick = {
                                println("点击bottom bar 1")
                            }) {
                                Icon(Icons.Default.Settings, contentDescription = "")
                            }
                            IconButton(modifier = Modifier.weight(1f) , onClick = {
                                println("点击bottom bar 2")
                            }) {
                                Icon(Icons.Default.AccountBox, contentDescription = "")
                            }
                            IconButton(modifier = Modifier.weight(1f), onClick = {
                                println("点击bottom bar 3")
                            }) {
                                Icon(Icons.Default.Add, contentDescription = "")
                            }
                        }
                    }
                }
            )
        }

    }
}
相关推荐
千里马学框架5 天前
一起学 Android 14:ShellTransition 屏幕旋转过程深度剖析
android·智能手机·性能优化·framework·性能·屏幕旋转·rotation
美狐美颜SDK开放平台5 天前
开发直播APP时如何接入视频美颜SDK?开发流程与注意事项
android·人工智能·计算机视觉·音视频·直播美颜sdk
AFinalStone5 天前
Android7 SystemUI源码解析(七)Keyguard锁屏模块深度解析
android·systemui
致远ccc5 天前
Google Play 上架前如何测试 App?多国家 Android 环境测试
android·app测试·googleplay·多国家应用测试
ttyyttemo5 天前
Kotlin 协程中的 Job 结构化并发与取消
android
sun0077005 天前
tbox 4g/5g切换,导致wan ip 改变,导致车机旧网络不可用。需要重启车机才行
android
ai2work5 天前
ch23 综合复刻:从零做一个最小可用版本(capstone)
kotlin
其实防守也摸鱼5 天前
内网穿透与反向代理:原理、工具与实战指南
android·大数据·运维·安全·网络安全·自动化·渗透
ai2work5 天前
ch21 签名、校验与发版
kotlin
AFinalStone5 天前
Android7 SystemUI 源码解析(四)NavigationBar 导航栏与 SystemBars
android·systemui