天天看點

自定義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);