http://blog.csdn.net/admin_/article/details/7853588
方法一(这种方法可以处理popupwindows dimiss的时候一些其他的操作,比如让其他控件的隐藏,消失等):
代码如下popupWindow.setFocusable(false);//focusable要为false(不设置默认的就是False);//这是Activity 的OnTouchEvent。OnTouchEvent代表的是Activity 获得事件(即为PopupWindow之外)
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
popupWindow = null;
}
return super.onTouchEvent(event);
}
方法二:设置popupWindow参数(这种方法只能让自身消失,不能够提供其他伴随操作,比如让其他控件的隐藏,消失等)
pop = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
pop.setBackgroundDrawable(new BitmapDrawable());
pop.setOutsideTouchable(true);
popupwindow点击空白处如何自动消失?
下面这个方法,亲测有效!http://blog.sina.com.cn/s/blog_455d67110101rd38.html
Popupwindow如果需要点击空白处自动消失,需要设置两个函数
1、customPopWindow.setFocusable(true);该函数也可以在构造函数中设置,如:mPopupWindow
= new PopupWindow(popunwindwow,LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT,true);最后一个参数true即为设定Focusable属性。
2、customPopWindow.setBackgroundDrawable(new BitmapDrawable());
此处需要注意:上述两个方法必须放在showAtLocation()方法之前,才能起作用。