1. 程式人生 > >關於點選popupwindow以外區域 popupwindow自動消失問題

關於點選popupwindow以外區域 popupwindow自動消失問題

方法一(這種方法可以處理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);