代碼如下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);