Basic learning of Compose for Android development - topBar of the basic usage of Scaffold scaffolding control

first picture

Look at the code again

package com.xiayiye5.composefirst.components

import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Edit
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout

/*
 * Copyright (c) 2022,[email protected] All Rights Reserved.
 * #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #                / _||||| -:- |||||- \              #
 * #               |   | \\\  -  #/ |   |              #
 * #               | \_|  ''\---/''  |_/ |             #
 * #               \  .-\__  '-'  ___/-. /             #
 * #             ___'. .'  /--.--\  `. .'___           #
 * #          ."" '<  `.___\_<|>_/___.' >' "".         #
 * #         | | :  `- \`.;`\ _ /`;.`/ - ` : | |       #
 * #         \  \ `_.   \_ __\ /__ _/   .-` /  /       #
 * #     =====`-.____`.___ \_____/___.-`___.-'=====    #
 * #                       `=---='                     #
 * #     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   #
 * #                                                   #
 * #               佛祖保佑         永无BUG              #
 * #                                                   #
 */

/**
 * @author 下一页5(轻飞扬)
 * 创建时间:2022/5/7 19:44
 * 个人小站:http://yhsh.wap.ai(已挂)
 * 最新小站:http://www.iyhsh.icoc.in
 * 联系作者:企鹅 13343401268
 * 博客地址:http://blog.csdn.net/xiayiye5
 * 项目名称:ComposeFirst
 * 文件包名:com.xiayiye5.composefirst.components
 * 文件说明:Scaffold脚手架控件基本用法之topBar
 */

@Composable
fun ScaffoldTopBarSamples() {
    Scaffold(topBar = {
        TopAppBar(title = {
            Text(text = "我是标题栏")
        }, navigationIcon = {
            Icon(
                imageVector = Icons.Default.ArrowBack,
                contentDescription = null,
            )
        }, actions = {
            Icon(imageVector = Icons.Default.Edit, contentDescription = null)
            Text(text = "编辑", Modifier.padding(15.dp, 0.dp, 20.dp, 0.dp))
        })
    }, bottomBar = {
        BottomAppBar() {
            Text(text = "我是底部内容")
        }
    }, modifier = Modifier.height(480.dp)) {
        ConstraintLayout(
            modifier = Modifier
                .fillMaxWidth()
                .fillMaxHeight()
        ) {
            val (centerContent) = createRefs()
            Text(text = "我是要显示的内容", Modifier.constrainAs(centerContent) {
                start.linkTo(parent.start)
                top.linkTo(parent.top)
                end.linkTo(parent.end)
                bottom.linkTo(parent.bottom)
            })
        }
    }
}

@Preview
@Composable
fun ScaffoldSamplesPreview() {
    ScaffoldTopBarSamples()
}

Guess you like

Origin blog.csdn.net/xiayiye5/article/details/125129565