首先要给popwindow设置背景图片为透明,然后让它点击外面触发这个事件为true
mPopupWindow.setBackgroundDrawable(getDrawable());
mPopupWindow.setOutsideTouchable(true);
/**
* 生成一个 透明的背景图片
* @return
*/
private Drawable getDrawable(){
ShapeDrawable bgdrawable =new ShapeDrawable(new OvalShape());
bgdrawable.getPaint().setColor(cxt.getResources().getColor(android.R.color.transparent));
return bgdrawable;
}
这样点击popwindow之外的话就会让它消失,测试已通过。