ใช้ส่วนตัดในมุมมองและเขียน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หากแอปมีทั้งโค้ด Compose และ View คุณอาจต้องระบุอย่างชัดเจน
ว่าแต่ละรายการควรใช้ Inset ของระบบใด และตรวจสอบว่าได้ส่ง Inset ไปยัง View ที่เป็นระดับเดียวกัน
การลบล้างระยะขอบเริ่มต้น
คุณอาจต้องลบล้างระยะขอบเริ่มต้นเมื่อหน้าจอมีทั้ง View และโค้ด Compose ในลำดับชั้นเดียวกัน ในกรณีนี้ คุณต้องระบุอย่างชัดเจนว่า
เลย์เอาต์ใดควรใช้ระยะขอบ และเลย์เอาต์ใดควรละเว้น
เช่น หากเลย์เอาต์ชั้นนอกสุดเป็นเลย์เอาต์ Android View คุณควร
ใช้ Inset ในระบบ View และไม่สนใจ Inset สำหรับ Compose
หรือหากเลย์เอาต์ชั้นนอกสุดเป็น Composable คุณควรใช้
ระยะขอบใน Compose และเว้นที่ว่างสำหรับ Composable AndroidView
ตามนั้น
โดยค่าเริ่มต้น ComposeView
แต่ละรายการจะใช้ขอบทั้งหมดที่ระดับการใช้งาน WindowInsetsCompat
หากต้องการเปลี่ยนลักษณะการทำงานเริ่มต้นนี้ ให้ตั้งค่า
AbstractComposeView.consumeWindowInsets
เป็น false
การจัดส่งการแทรกที่เข้ากันได้แบบย้อนหลังสำหรับมุมมอง
หากแอปมีโค้ด Views คุณอาจต้องยืนยันว่ามีการส่ง Insets
ไปยัง View ที่อยู่ระดับเดียวกันในอุปกรณ์ที่ใช้ 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```"]]