自定义PopupWindow全屏显示

自定义PopupWindow的时候发现一个问题:系统状态栏没有被遮盖,给人的感觉不是很友好。

1、自定义的Popupwindow部分代码:

    public void show() {
        this.showAtLocation(activity.getWindow().getDecorView(), Gravity.BOTTOM, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
    }

    private void initView() {
        //初始化控件
        initViewSetting();
        //初始化数据
        initData();
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(WindowManager.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        //实例化一个ColorDrawable颜色为透明(半透明是0xb0000000)
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
    }

2、显示弹窗的部分代码

 TokenPopupWindow tokenPopupWindow = new TokenPopupWindow((Activity) context,tokenInfo.getTokenSN());
                    tokenPopupWindow.setClippingEnabled(false);
                    tokenPopupWindow.show();

3、解决弹窗全屏显示的关键代码,二者缺一不可

this.showAtLocation(activity.getWindow().getDecorView(), Gravity.BOTTOM, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
  tokenPopupWindow.setClippingEnabled(false);

猜你喜欢

转载自blog.csdn.net/subofeng/article/details/93198686