【问题标题】:Soft Navigation Bar Overlays App in LollipopLollipop 中的软导航栏覆盖应用程序
【发布时间】:2014-10-29 19:39:35
【问题描述】:

在我的 Nexus 5 上的 Android Lollipop(最新开发预览版,构建 LPX13D)中,我正在编写的应用似乎隐藏在软导航栏(带有返回、主页和应用历史按钮的栏)下方。我无法在运行 Kit Kat 的 Nexus 4 上复制此内容(导航栏后面没有隐藏任何内容)。

我要如何缩小应用的视口才能使我的所有内容都能在屏幕上看到?

编辑:

根据要求提供屏幕截图。

运行 Kit Kat (4.4.4) 的 Nexus 4:

运行 Lollipop 的 Nexus 5(5.0,LPX13D):

【问题讨论】:

    标签: android android-5.0-lollipop


    【解决方案1】:

    经过大量测试,我发现这是 SlidingMenu 库的问题。除了涉及滑动操作栏的选项之外,我无法修复它,也无法找到根本原因。

    我在图书馆的 GitHub 上发布了一个问题,希望能得到图书馆的修复或解决方案。

    https://github.com/jfeinstein10/SlidingMenu/issues/680

    编辑 (2014-11-04): 作为快速跟进,一位用户在上述问题中发帖称它与 Material 主题有关,并且使用 Holo 主题将避免此问题.我能够证实这一点。因此,在将 SlidingMenu 与 Material 主题一起使用之前,我们可能需要等待修复。

    【讨论】:

    【解决方案2】:

    尝试将android:fitsSystemWindows="true" 添加到 Activity 布局文件的根视图中。

    【讨论】:

    • 这似乎不起作用。我在几个不同布局的不同活动中尝试了它,但对它们中的任何一个都不起作用。不过,感谢您的回答。
    • 您能否发布一张 Nexus 5 和 Nexus 4 的裁剪图,以便我们了解您的意思。
    • NavigationBar 透明吗?
    • 抱歉耽搁了。我将请求的屏幕截图上传到问题中(仅更改操作栏以删除标识徽标,因为应用程序未完成)。两个滚动视图都滚动到最底部,但它发生在所有视图类型中。不,我没有使用透明的 NavigationBar。再次感谢您查看此内容。
    • 谢谢,此解决方案适用于旧版本 android.support.v4.widget.DrawerLayout 中的类似错误
    【解决方案3】:

    如果有人对 android.support.v4 有类似问题 - 只需将支持库更新到 22.2.1 版本即可。

    【讨论】:

      【解决方案4】:

      经过数小时的研发,我们找到了解决方案

      如果您使用的是ResideMenu 库,那么只需在ResideMenu.java 中添加此方法即可修复它

        @Override
      protected boolean fitSystemWindows(Rect insets) {
          int bottomPadding = insets.bottom;
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
              Resources resources = getResources();
              int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
              if (resourceId > 0) {
                  bottomPadding += resources.getDimensionPixelSize(resourceId);
              }
          }
          this.setPadding(viewActivity.getPaddingLeft() + insets.left, viewActivity.getPaddingTop() + insets.top,
                  viewActivity.getPaddingRight() + insets.right, viewActivity.getPaddingBottom() + bottomPadding);
          insets.left = insets.top = insets.right = insets.bottom = 0;
          return true;
      }
      

      【讨论】:

        【解决方案5】:

        目前对我有用的简单解决方案是, 在 setContentView 之后在 OnCreate() 中获取导航栏高度并将填充设置为活动的根布局。

        .....
                int navHeight = getNavHeight();
                if (navHeight > 0) {
                    (findViewById(R.id.rlMain)).setPadding(0, 0, 0, navHeight);
                }
        .....
            private int getNavHeight() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
                    return 0;
                try {
        
                    Resources resources = getResources();
                    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
                    if (resourceId > 0) {
                        boolean hasMenuKey = ViewConfiguration.get(getApplicationContext()).hasPermanentMenuKey();
                        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        
                        if (!hasMenuKey && !hasBackKey) {
                            return resources.getDimensionPixelSize(resourceId);
                        }
                    }
                } catch (Exception ex) {
                    return 0;
                }
                return 0;
            }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-01-21
          • 2012-11-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多