varexclusionRects=listOf(rect1,rect2,rect3)funonLayout(changedCanvas:Boolean,left:Int,top:Int,right:Int,bottom:Int){// Update rect bounds and the exclusionRects listsetSystemGestureExclusionRects(exclusionRects)}funonDraw(canvas:Canvas){// Update rect bounds and the exclusionRects listsetSystemGestureExclusionRects(exclusionRects)}
Java
List<Rect>exclusionRects;publicvoidonLayout(booleanchangedCanvas,intleft,inttop,intright,intbottom){// Update rect bounds and the exclusionRects listsetSystemGestureExclusionRects(exclusionRects);}publicvoidonDraw(Canvascanvas){// Update rect bounds and the exclusionRects listsetSystemGestureExclusionRects(exclusionRects);}
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Ensure compatibility with gesture navigation\n\nBeginning with Android 10 (API level 29), the Android system supports fully\ngesture-based navigation. There are two things app developers must do to ensure\ntheir apps are compatible with this feature:\n\n- Extend app content from edge to edge.\n- Handle conflicting app gestures.\n\nIn addition, Android 13 (API level 33) introduces a\n[predictive back gesture](/guide/navigation/predictive-back-gesture) for Android\ndevices such as phones, large screens, and foldables that is part of a multiyear\nrelease. App developers can take steps to ensure that their apps support the\npredictive back gesture.\n\nProvide edge-to-edge app content\n--------------------------------\n\nTo take advantage of the additional screen space made available by the floating\nnavigation bar, you need to configure certain changes in your app.\n\nSee [Display content edge-to-edge in your app](/training/gestures/edge-to-edge)\nfor details.\n\nHandle conflicting app gestures\n-------------------------------\n\nThe gesture navigation model might conflict with gestures that were previously\nused by app developers. You might need to make adjustments to your app's user\ninterface as a result.\n\n### Conflicts with back gestures\n\nThe new system gesture for back is an inward swipe from either the left or the\nright edge of the screen. This might interfere with app navigation elements in\nthose areas. To maintain functionality of elements on the left and right edges\nof the screen, opt out of the back gesture selectively by indicating to the\nsystem which regions need to receive touch input. You can do this by passing a\n`List\u003cRect\u003e` to the [`View.setSystemGestureExclusionRects()`](/reference/android/view/View#setSystemGestureExclusionRects(java.util.List%3Candroid.graphics.Rect%3E))\nAPI introduced in Android 10. This method is also available in [`ViewCompat`](/reference/androidx/core/view/ViewCompat) as of\n`androidx.core:core:1.1.0-dev01`.\n\nFor example: \n\n### Kotlin\n\n```kotlin\nvar exclusionRects = listOf(rect1, rect2, rect3)\n\nfun onLayout(\n changedCanvas: Boolean, left: Int, top: Int, right: Int, bottom: Int) {\n // Update rect bounds and the exclusionRects list\n setSystemGestureExclusionRects(exclusionRects)\n}\n\nfun onDraw(canvas: Canvas) {\n // Update rect bounds and the exclusionRects list\n setSystemGestureExclusionRects(exclusionRects)\n}\n```\n\n### Java\n\n```java\nList\u003cRect\u003e exclusionRects;\n\npublic void onLayout(\n boolean changedCanvas, int left, int top, int right, int bottom) {\n // Update rect bounds and the exclusionRects list\n setSystemGestureExclusionRects(exclusionRects);\n}\n\npublic void onDraw(Canvas canvas) {\n // Update rect bounds and the exclusionRects list\n setSystemGestureExclusionRects(exclusionRects);\n}\n```\n| **Note:** The `DrawerLayout` and `SeekBar` components support automatic opt-out behavior out of the box.\n\n### Conflicts with home or quick-switch gestures\n\nThe new system gestures for home and quick switch both involve swipes at the\nbottom of the screen in the space previously occupied by the nav bar. Apps\ncan't opt out of these gestures as they can with the back gesture.\n\nTo mitigate this problem, Android 10 introduces the\n[`WindowInsets.getMandatorySystemGestureInsets()`](/reference/android/view/WindowInsets.Type#mandatorySystemGestures())\nAPI, which informs apps of the touch recognition thresholds.\n\n### Games and other non-View apps\n\nGames and other apps that don't have a view hierarchy often require the user to\nswipe near the system gesture areas. In those cases, games can use\n[`Window.setSystemGestureExclusionRects()`](/reference/android/view/Window#setSystemGestureExclusionRects(java.util.List%3Candroid.graphics.Rect%3E))\nto exclude areas that overlap with areas reserved for system gestures. Games\nmust make sure to only exclude these areas when necessary, such as during\ngameplay.\n\nIf a game requires the user to swipe near the home gesture area, the app can\nrequest to be laid out in [immersive mode](/training/system-ui/immersive#immersive). This disables the system gestures\nwhile the user is interacting with the game, but lets the user re-enable\nthe system gestures by swiping from the bottom of the screen.\n\nUpdate your app to support the predictive back gesture\n------------------------------------------------------\n\nAndroid 13 (API level 33) introduces a predictive back gesture for Android\ndevices such as phones, large screens, and foldables. The predictive back\ngesture is part of a multiyear release. When fully implemented, this feature\nlets users preview the destination or other result of a back gesture before\nthey fully complete it, allowing them to decide whether to continue or stay in\nthe current view.\n\nSee\n[Add support for the predictive back gesture](/guide/navigation/predictive-back-gesture)\nfor details.\n\nAdditional resources\n--------------------\n\nTo learn more about gesture navigation, see the following:\n\n### Blog posts\n\n- [Gesture Navigation: handling visual overlaps (II)](https://medium.com/androiddevelopers/gesture-navigation-handling-visual-overlaps-4aed565c134c)\n\n### Videos\n\n- [Android 10: Gestural navigation](https://www.youtube.com/watch?v=Ljtz7T8R_Hk)\n- [Dark theme \\& gesture navigation (Google I/O '19)](https://www.youtube.com/watch?v=OCHEjeLC_UY)"]]