Scaffold
ใน Material Design เฟรมเวิร์กคือโครงสร้างพื้นฐานที่ให้บริการแพลตฟอร์มมาตรฐานสําหรับอินเทอร์เฟซผู้ใช้ที่ซับซ้อน ธีมเป็นองค์ประกอบที่เชื่อมโยงส่วนต่างๆ ของ UI เช่น แถบแอปและปุ่มการดำเนินการแบบลอยตัวเข้าด้วยกัน เพื่อให้แอปมีรูปลักษณ์และความรู้สึกที่สอดคล้องกัน
ตัวอย่าง
คอมโพสิเบิล Scaffold
มี API ที่ใช้งานง่ายซึ่งคุณสามารถใช้เพื่อรวบรวมโครงสร้างของแอปตามหลักเกณฑ์ของ Material Design ได้อย่างรวดเร็ว
Scaffold
ยอมรับ Composable หลายรายการเป็นพารามิเตอร์ ซึ่งรวมถึงแอปต่อไปนี้
topBar
: แถบแอปที่ด้านบนของหน้าจอbottomBar
: แถบแอปที่ด้านล่างของหน้าจอfloatingActionButton
: ปุ่มที่วางเหนือมุมขวาล่างของหน้าจอซึ่งคุณใช้เพื่อแสดงการดำเนินการหลักได้
นอกจากนี้ คุณยังส่งเนื้อหา Scaffold
ไปยังคอนเทนเนอร์อื่นๆ ได้ด้วย โดยจะส่ง PaddingValues
ไปยัง content
lambda ที่คุณควรใช้กับคอมโพสิชันรูทของเนื้อหาเพื่อจำกัดขนาด
ตัวอย่างต่อไปนี้แสดงการใช้งาน Scaffold
ที่สมบูรณ์ โดยประกอบด้วยแถบด้านบนของแอป แถบด้านล่างของแอป และปุ่มการทำงานแบบลอย
@Composable fun ScaffoldExample() { var presses by remember { mutableIntStateOf(0) } Scaffold( topBar = { TopAppBar( colors = topAppBarColors( containerColor = MaterialTheme.colorScheme.primaryContainer, titleContentColor = MaterialTheme.colorScheme.primary, ), title = { Text("Top app bar") } ) }, bottomBar = { BottomAppBar( containerColor = MaterialTheme.colorScheme.primaryContainer, contentColor = MaterialTheme.colorScheme.primary, ) { Text( modifier = Modifier .fillMaxWidth(), textAlign = TextAlign.Center, text = "Bottom app bar", ) } }, floatingActionButton = { FloatingActionButton(onClick = { presses++ }) { Icon(Icons.Default.Add, contentDescription = "Add") } } ) { innerPadding -> Column( modifier = Modifier .padding(innerPadding), verticalArrangement = Arrangement.spacedBy(16.dp), ) { Text( modifier = Modifier.padding(8.dp), text = """ This is an example of a scaffold. It uses the Scaffold composable's parameters to create a screen with a simple top app bar, bottom app bar, and floating action button. It also contains some basic inner content, such as this text. You have pressed the floating action button $presses times. """.trimIndent(), ) } } }
การติดตั้งใช้งานนี้จะปรากฏดังนี้
