ボトムシート
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ボトムシートを実装する場合は ModalBottomSheet
コンポーザブルを使用できます。
content
スロットでは、ColumnScope
を使用してシート コンテンツのコンポーザブルを一列にレイアウトできます。
ModalBottomSheet(onDismissRequest = { /* Executed when the sheet is dismissed */ }) {
// Sheet content
}
シートの状態をプログラムで制御する
シートをプログラムで展開したり折りたたんだりするには、SheetState
を使用します。rememberSheetState
を使用して、sheetState
パラメータで ModalBottomSheet
に渡す必要のある SheetState
のインスタンスを作成できます。SheetState
は、現在のシートの状態に関連するプロパティだけでなく、show
関数と hide
関数へのアクセスを提供します。これらの suspend 関数は CoroutineScope
を必要とし(たとえば rememberCoroutineScope
を使用)、UI イベントに応じて呼び出すことができます。ボトムシートを非表示にするときに、コンポジションから ModalBottomSheet
を削除するようにしてください。
val sheetState = rememberModalBottomSheetState()
val scope = rememberCoroutineScope()
var showBottomSheet by remember { mutableStateOf(false) }
Scaffold(
floatingActionButton = {
ExtendedFloatingActionButton(
text = { Text("Show bottom sheet") },
icon = { Icon(Icons.Filled.Add, contentDescription = "") },
onClick = {
showBottomSheet = true
}
)
}
) { contentPadding ->
// Screen content
if (showBottomSheet) {
ModalBottomSheet(
onDismissRequest = {
showBottomSheet = false
},
sheetState = sheetState
) {
// Sheet content
Button(onClick = {
scope.launch { sheetState.hide() }.invokeOnCompletion {
if (!sheetState.isVisible) {
showBottomSheet = false
}
}
}) {
Text("Hide bottom sheet")
}
}
}
}
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-08-27 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-27 UTC。"],[],[],null,["If you want to implement a [bottom sheet](https://m3.material.io/components/bottom-sheets/overview), you can use the\n[`ModalBottomSheet`](/reference/kotlin/androidx/compose/material3/package-summary#ModalBottomSheet(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.material3.SheetState,androidx.compose.ui.unit.Dp,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.unit.Dp,androidx.compose.ui.graphics.Color,kotlin.Function0,androidx.compose.foundation.layout.WindowInsets,androidx.compose.material3.ModalBottomSheetProperties,kotlin.Function1)) composable.\n\nYou can use the `content` slot, which uses a [`ColumnScope`](/reference/kotlin/androidx/compose/foundation/layout/ColumnScope) to layout sheet\ncontent composables in a column:\n\n\n```kotlin\nModalBottomSheet(onDismissRequest = { /* Executed when the sheet is dismissed */ }) {\n // Sheet content\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/layouts/MaterialLayoutSnippets.kt#L364-L366\n```\n\n\u003cbr /\u003e\n\nControl sheet state programmatically\n\nTo programmatically expand and collapse the sheet, use\n[`SheetState`](/reference/kotlin/androidx/compose/material3/SheetState). You can use [`rememberSheetState`](/reference/kotlin/androidx/compose/material3/package-summary#rememberSheetState(kotlin.Boolean,kotlin.Function1)) to create an instance\nof `SheetState` that should be passed to `ModalBottomSheet` with the\n`sheetState` parameter. `SheetState` provides access to the [`show`](/reference/kotlin/androidx/compose/material3/SheetState#show()) and\n[`hide`](/reference/kotlin/androidx/compose/material3/SheetState#hide()) functions, as well as properties related to the current sheet\nstate. These suspending functions require a `CoroutineScope` --- for example,\nusing [`rememberCoroutineScope`](/reference/kotlin/androidx/compose/runtime/package-summary#remembercoroutinescope) --- and you can call them in response to UI\nevents. Make sure to remove the `ModalBottomSheet` from composition upon hiding\nthe bottom sheet.\n\n\n```kotlin\nval sheetState = rememberModalBottomSheetState()\nval scope = rememberCoroutineScope()\nvar showBottomSheet by remember { mutableStateOf(false) }\nScaffold(\n floatingActionButton = {\n ExtendedFloatingActionButton(\n text = { Text(\"Show bottom sheet\") },\n icon = { Icon(Icons.Filled.Add, contentDescription = \"\") },\n onClick = {\n showBottomSheet = true\n }\n )\n }\n) { contentPadding -\u003e\n // Screen content\n\n if (showBottomSheet) {\n ModalBottomSheet(\n onDismissRequest = {\n showBottomSheet = false\n },\n sheetState = sheetState\n ) {\n // Sheet content\n Button(onClick = {\n scope.launch { sheetState.hide() }.invokeOnCompletion {\n if (!sheetState.isVisible) {\n showBottomSheet = false\n }\n }\n }) {\n Text(\"Hide bottom sheet\")\n }\n }\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/layouts/MaterialLayoutSnippets.kt#L370-L408\n```\n\n\u003cbr /\u003e"]]