关于Android中Navigation Bar遮挡PopupW

2017-08-03  本文已影响224人  安卓Boy

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

现象描述

navigation_issue.png

实现代码

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>

修改好的效果

navigation_bar_good.png

更佳的方法

popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

注意:这个方法不会影响到状态栏的颜色改变,而第一种方法会。

上一篇 下一篇

猜你喜欢

热点阅读