Android具有View.setSystemGestureExclusionRects()
API,可以在Android 10的指定区域禁用“后退”手势。此API是在API级别29中添加的,因此在使用它之前,我们必须检查SDK版本:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
view.systemGestureExclusionRects = listOf(...)
}
The official documents says,即ViewCompat
类还包含setSystemGestureExclusionRects()
方法。这样可以避免检查SDK版本:
ViewCompat.setSystemGestureExclusionRects(...)
此方法必须从androidx.core:core:1.1.0-dev01
开始可用。在我的项目中,我具有implementation 'androidx.core:core:1.1.0'
依赖项。版本“ 1.1.0”晚于“ 1.1.0-dev01”,但是缺少ViewCompat.setSystemGestureExclusionRects()
方法。为什么?
1.2.0
中找到它。例如,here is the ViewCompat
from 1.2.0-rc01
,当前最新版本(截至2020年1月10日)。它具有您想要的功能...尽管它几乎就是您的代码片段所显示的内容,仅在Java中:ViewCompat
FWIW,我提交了1.2.0-rc01
。