修復Android中Navigation Bar遮擋PopupWindow的問題

jopen 8年前發布 | 26K 次閱讀 Android開發 移動開發 PopupWindow

最近遇到了一個問題,關于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);
}

其實和具體的實現代碼沒有關系,重點是修改主題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>

修改好的效果

demo源碼

Navigation Bar Issue Demo

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

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!