25

在 Android 10 中,用户可以启用全屏手势模式。我想检测设备是否处于全屏手势模式。我在文档中找不到任何东西。如何在运行时以编程方式进行?

Java 或 kotlin 语言的答案都可以。

任何官方 API 或解决方法...

4

3 回答 3

18

您可以使用以下代码检查手势或导航模式

    public static int isEdgeToEdgeEnabled(Context context) {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("config_navBarInteractionMode", "integer", "android");
        if (resourceId > 0) {
            return resources.getInteger(resourceId);
        }
        return 0;
    }

isEdgeToEdgeEnabled 函数返回的值如下:

  • 0 : 导航显示有 3 个按钮

  • 1 : 导航显示 2 按钮(Android P 导航模式)

  • 2:全屏手势(Android Q上的手势)

于 2020-03-18T04:11:21.933 回答
0

我发现这篇文章在解释它们是什么WindowInsets以及如何使用它们方面非常有用。

基本上我检查左手势插入是否大于0,如果是,则系统正在使用手势类型导航。左右手势插入必须大于0手势类型导航,因为您从右侧或左侧滑动才能返回。

int gestureLeft = 0;

if (Build.VERSION.SDK_INT >= 29) {
    gestureLeft = this.getWindow().getDecorView().getRootWindowInsets().getSystemGestureInsets().left;
}

if (gestureLeft == 0) {
    // Doesn't use gesture type navigation
} else {
    // Uses gesture type navigation
}

显然,必须渲染窗口才能使其正常工作。OnApplyWindowInsetsListener如果您希望它在窗口呈现后立即运行,您可以将其添加到其中。

注意:我尝试使用getSystemGestureInsets().bottom,但即使我没有使用手势类型导航,它也会返回一个非零值。

于 2021-12-29T03:36:17.063 回答
-1

根据文档,如果有任何非零插图,则有一种hasInsets()方法返回。https://developer.android.com/reference/android/view/WindowInsets#hasInsets()我们可以这样使用trueWindowInsets



view.rootWindowInsets.hasInsets()

希望这可以帮助!

于 2020-06-27T23:10:50.593 回答