ビューと Compose でインセットを使用する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
アプリに Compose コードと View コードの両方が含まれている場合は、それぞれがどのシステム インセットを使用するかを明示し、インセットが兄弟ビューにディスパッチされるようにする必要があります。
デフォルトのインセットをオーバーライドする
画面の同じ階層に View と Compose の両方のコードがある場合は、デフォルトのインセットをオーバーライドする必要があるかもしれません。この場合、どちらがインセットを使用し、どちらがインセットを無視するかを明示する必要があります。
たとえば、最も外側のレイアウトが Android View レイアウトの場合、View システムでインセットを使用し、Compose では無視する必要があります。また、最外側のレイアウトがコンポーザブルである場合は、Compose でインセットを使用し、それに応じて AndroidView
コンポーザブルをパディングする必要があります。
デフォルトでは、各 ComposeView
は WindowInsetsCompat
レベルの消費量ですべてのインセットを消費します。このデフォルトの動作を変更するには、AbstractComposeView.consumeWindowInsets
を false
に設定します。
ビューの下位互換性のあるインセット ディスパッチ
アプリに Views コードが含まれている場合は、Android 10(API レベル 29)以下を搭載したデバイスで、インセットが兄弟ビューにディスパッチされることを確認する必要があるかもしれません。詳しくは、エッジ ツー エッジのビューガイドをご覧ください。
システムバー アイコン
enableEdgeToEdge
を呼び出すと、デバイスのテーマが変更されたときにシステムバーのアイコンの色が更新されます。
エッジ ツー エッジにする場合は、アプリの背景とコントラストをなすように、システムバー アイコンの色を手動で更新する必要があるかもしれません。たとえば、ライト ステータスバー アイコンを作成するには:
Kotlin
WindowCompat.getInsetsController(window, window.decorView)
.isAppearanceLightStatusBars = false
Java
WindowCompat.getInsetsController(window, window.getDecorView())
.setAppearanceLightStatusBars(false);
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-08-21 UTC。
[null,null,["最終更新日 2025-08-21 UTC。"],[],[],null,["# Use insets in Views and Compose\n\nIf your app contains both Compose and View code, you may need to be explicit\nabout which system insets each one should consume and ensure that insets are\ndispatched to sibling views.\n\nOverriding default insets\n-------------------------\n\nYou may need to override default insets when your screen has both Views and\nCompose code in the same hierarchy. In this case, you need to be explicit in\nwhich one should consume the insets, and which one should ignore them.\n\nFor example, if your outermost layout is an Android View layout, you should\nconsume the insets in the View system and ignore them for Compose.\nAlternatively, if your outermost layout is a composable, you should consume the\ninsets in Compose, and pad the `AndroidView` composables accordingly.\n\nBy default, each `ComposeView` consumes all insets at the\n`WindowInsetsCompat` level of consumption. To change this default behavior, set\n[`AbstractComposeView.consumeWindowInsets`](/reference/kotlin/androidx/compose/ui/platform/AbstractComposeView#(androidx.compose.ui.platform.AbstractComposeView).consumeWindowInsets())\nto `false`.\n\nBackward compatible inset dispatching for views\n-----------------------------------------------\n\nIf your app contains Views code, you may need to confirm that insets are dispatched\nto sibling views on devices that run Android 10 (API level 29) or lower. See the\n[edge-to-edge Views guide](/develop/ui/views/layout/edge-to-edge#backward-compatible-dispatching)\nfor more information.\n\nSystem bar icons\n----------------\n\nCalling `enableEdgeToEdge` ensures system bar icon colors update when the device\ntheme changes.\n\nWhile going edge-to-edge, you might need to manually update the system bar icon\ncolors so they contrast with your app's background. For example, to create light\nstatus bar icons: \n\n### Kotlin\n\n```kotlin\nWindowCompat.getInsetsController(window, window.decorView)\n .isAppearanceLightStatusBars = false\n```\n\n### Java\n\n```java\nWindowCompat.getInsetsController(window, window.getDecorView())\n .setAppearanceLightStatusBars(false);\n```"]]