修复Android中Navigation Bar遮挡PopupWindow的问题

jopen 8年前

最近遇到了一个问题,关于Navigation Bar遮挡PopupWindow的问题,问题不难,粗略做一点总结。

现象描述

  • 问题应该出现在5.0 Lollipop版本及以上
  • 遮挡的现象如下图,Navigation Bar位于了PopupWindow的上层,明显是一种问题。

我的实现代码

private void showPopupWindow() {      if (mPopupWindow == null) {        View contentView = LayoutInflater.from(this).inflate(R.layout.popup_window_content, null);            mPopupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT,500, true);          mPopupWindow.setBackgroundDrawable(new BitmapDrawable());      }      mPopupWindow.showAtLocation(findViewById(R.id.contentContainer), Gravity.BOTTOM, 0,0);  }
</div>

其实和具体的实现代码没有关系,重点是修改主题style。

修改style

修改v21/styles.xml(如没有,可以创建),将 android:windowDrawsSystemBarBackgrounds 修改为 false 。

<style name="AppTheme.NoActionBar">      <item name="windowActionBar">false</item>      <item name="windowNoTitle">true</item>      <item name="android:windowDrawsSystemBarBackgrounds">false</item>      <item name="android:statusBarColor">@android:color/transparent</item>  </style>
</div>

修改好的效果

demo源码

Navigation Bar Issue Demo

</div>

来自: http://droidyue.com/blog/2016/01/10/android-navigation-bar-popupwindow-issue/