Compose_10--认识脚手架Scaffold

Scaffold是Compose的脚手架,基本实现了基本材料设计的可视化布局结构,包括顶部应用程序栏和底部栏、抽屉和浮动操作按钮等。

import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Dp

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun ComposeScaffold(
    modifier: Modifier = Modifier,
    scaffoldState: ScaffoldState = rememberScaffoldState(),
    topBar: @Composable (() -> Unit) = {},
    bottomBar: @Composable (() -> Unit) = {},
    snackbarHost: @Composable (SnackbarHostState) -> Unit = { SnackbarHost(it) },
    floatingActionButton: @Composable (() -> Unit) = {},
    floatingActionButtonPosition: FabPosition = FabPosition.End,
    isFloatingActionButtonDocked: Boolean = false,
    drawerContent: @Composable (ColumnScope.() -> Unit)? = null,
    drawerShape: Shape = MaterialTheme.shapes.large,
    drawerElevation: Dp = DrawerDefaults.Elevation,
    drawerBackgroundColor: Color,
    drawerContentColor: Color,
    drawerScrimColor: Color,
    backgroundColor: Color,
    contentColor: Color,
    content: @Composable (PaddingValues) -> Unit
){
    /**
     *  Scaffold 是Compose的脚手架,基本实现了基本材料设计的可视化布局结构
     *  顶部应用程序栏和底部栏、抽屉和浮动操作按钮等都在Scaffold里面
     */
    Scaffold(
        modifier = modifier, // 可选修饰符
        scaffoldState = scaffoldState,  // 状态
        topBar = topBar,  // 顶部程序栏
        bottomBar = bottomBar,  // 底部栏
        // 通过SnackbarHostState.showSnackbar推送显示,可以做类似吐司提示
        snackbarHost = snackbarHost,
        floatingActionButton = floatingActionButton,  // 浮动操作按钮
        floatingActionButtonPosition = floatingActionButtonPosition, // 浮动操作按钮位置
        // 如果存在底部栏,则floatingActionButton是否应与底部栏重叠半个高度。如果没有底部栏或浮动操作按钮,则忽略。
        isFloatingActionButtonDocked = isFloatingActionButtonDocked,
        drawerContent = drawerContent,  // 抽屉内容
        drawerShape = drawerShape,  // 抽屉形状
        drawerElevation = drawerElevation, // 抽屉阴影大小
        drawerBackgroundColor = drawerBackgroundColor, // 抽屉背景颜色
        drawerContentColor = drawerContentColor,  // 抽屉内容的颜色
        // 抽屉打开时遮盖内容的颜色(抽屉打开时与屏幕右边那段距离的颜色)
        drawerScrimColor = drawerScrimColor,
        backgroundColor = backgroundColor,  // 脚手架背景颜色
        contentColor = contentColor, // 脚手架内容颜色
        content = content  // 脚手架内容
    )
}

你可能感兴趣的:(Android-compose,gradle,android,android,studio)