Android P 的 Android 导航栏可见性 - 检测基于手势的导航

标签 android navigation android-9.0-pie

如何检测导航栏(用于无 Bazel 设备)是否可见?我尝试使用 Resource IdentifierSystem UI FlagKeyCharacterMap 为导航栏提供不同的解决方案,但它对我不起作用。在 Andorid P 中,手势导航可用,它将隐藏导航栏,导航功能将使用该手势运行。有什么解决方案可以检测到这一点吗?

最佳答案

我使用两种手势导航方法在小米设备上测试了这段代码,对我来说它是有效的:

Point p = new Point();
        getWindow().getWindowManager().getDefaultDisplay().getRealSize(p);
        ConstraintLayout container = findViewById(your activity main view (e.g linearLayout));

        final TypedArray styledAttributes = getTheme().obtainStyledAttributes(
                new int[]{android.R.attr.actionBarSize});
        int mActionBarSize = (int) styledAttributes.getDimension(0, 0);
        int height = container.getMeasuredHeight();
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        int result = 0;
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
if (height + mActionBarSize + result >= p.y) {
     //you have fullscreen gesture navigation
}else{
     //navigation bar or similiar
}

之所以可行,是因为该应用现在可以在屏幕上占据更大的尺寸,因此仅当手势导航方法不使“导航栏”成为背景时,它才有效。

请务必在 main 已加载且可见时使用它,否则它将返回 0。

关于Android P 的 Android 导航栏可见性 - 检测基于手势的导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54942371/

相关文章:

android - 哪里应该使用PageViewer?

java - 媒体投影需要 Android Pie 和 Q 中 ServiceInfo.FOREGROUND_SERVICE TYPE_MEDIA_PROJECTION 类型的前台服务

iOS 在导航堆栈中的 View Controller 之间循环

html - 使子菜单水平而不是垂直

c# - Visual Studio 2017 更新到 15.8.1/15.8.2 后的 Xamarin Android 应用项目构建问题

android - Android P Preview : Detected problems with API compatibility error 上的 Espresso 测试

android - 为 listview + Lazy List image 实现了 ViewHolder Pattern 但滚动仍然不流畅

android - 如何测试使用 Retrofit 和 Dagger2 的 REST API

android - 我怎样才能让我的按钮在 radiogroup 上居中?

android - 缓存数据android应用程序的最佳方法