PopupWindow 设置点击外部区域不消失

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

猜你喜欢

转载自blog.csdn.net/yh18668197127/article/details/84986793