為方便使用,許多內建的 Material 3 可組合項 (androidx.compose.material3
) 會根據可組合項在應用程式中的放置位置,自行處理插邊,符合 Material 規格。
插邊處理可組合函式
以下列出會自動處理插邊的 Material 元件。
應用程式列
TopAppBar
/SmallTopAppBar
/CenterAlignedTopAppBar
/MediumTopAppBar
/LargeTopAppBar
:由於系統資訊列會顯示在視窗頂端,因此會將系統資訊列的頂端和水平兩側套用為邊框間距。BottomAppBar
:將系統資訊列的底部和水平兩側套用為邊框間距。
內容容器
ModalDrawerSheet
/DismissibleDrawerSheet
/PermanentDrawerSheet
(模態導覽匣內的內容):將垂直和開始插邊套用至內容。ModalBottomSheet
: 套用底部插邊。NavigationBar
:套用「bottom」和「horizontal」插邊。NavigationRail
:套用 vertical 和 start 插邊。
Scaffold
根據預設,Scaffold
會提供插邊做為參數 paddingValues
,供您使用。Scaffold
不會將插邊套用至內容,您必須自行處理這項作業。
舉例來說,如要在 Scaffold
內的 LazyColumn
中使用這些插邊,請執行下列操作:
Scaffold { innerPadding -> // innerPadding contains inset information for you to use and apply LazyColumn( // consume insets as scaffold doesn't do it by default modifier = Modifier.consumeWindowInsets(innerPadding), contentPadding = innerPadding ) { // .. } }
以下影片顯示 Scaffold
內的 LazyColumn
,並停用及啟用無邊框螢幕:
覆寫預設插邊
您可以變更傳遞至可組合函式的 windowInsets
參數,藉此設定可組合函式的行為。這個參數可以是其他類型的視窗插邊,用來套用,也可以傳遞空白例項來停用:WindowInsets(0, 0, 0, 0)
。
舉例來說,如要停用 LargeTopAppBar
的插邊處理作業,請將 windowInsets
參數設為空白執行個體:
LargeTopAppBar( windowInsets = WindowInsets(0, 0, 0, 0), title = { Text("Hi") } )