PopupWindow 設定點選外部區域不消失
阿新 • • 發佈:2018-12-14
PopupWindow預設點選彈出外部區域dismiss
想要設定點選外部區域不消失需要設定底下三個方法
popupWindow.setOutsideTouchable(false);
popupWindow.setFocusable(false);
popupWindow.setTouchable(true);
完整程式碼
//建立 PopupWindow popupWindow = new PopupWindow(this); //設定 popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setContentView(LayoutInflater.from(this).inflate(R.layout.dialog_item01, null)); popupWindow.setOutsideTouchable(false); popupWindow.setFocusable(true); popupWindow.setTouchable(true); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE)); //顯示在控制元件下面 popupWindow.showAsDropDown(buttonUseCar); //顯示父控制元件中的指定位置 popupWindow.showAtLocation(cl,Gravity.TOP | Gravity.LEFT, 0, 100);
Android dialog和popupwiondow的區別
https://blog.csdn.net/yh18668197127/article/details/84985307