可以使用系统提供的inset方法,来改变系统手势的触发区域。
示例代码如下:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
View rootView = getWindow().getDecorView().getRootView();
Insets insets = rootView.getRootWindowInsets().getInsetsIgnoringVisibility(WindowInsets.Type.systemBars());
int left = insets.left;
int top = insets.top;
rootView.setSystemGestureExclusionRects(Collections.singletonList(new Rect(left, top, left + 200, top + 200)));
}
在这个示例中,我们使用了getRootWindowInsets方法来获取WindowInsets对象。然后,我们使用getInsetsIgnoringVisibility方法获取系统栏的区域,以便在触发系统手势时将其排除在触发区域外。最后,我们将Rect对象传递给setSystemGestureExclusionRects方法,以便在指定区域内排除系统手势触发。