這些為了點擊非PopupWindow區域,PopupWindow會消失的,如果沒有下面的
代碼的話,你會發現,當你把PopupWindow顯示出來了,無論你按多少次后退鍵
PopupWindow並不會關閉,而且退不出程序,加上下述代碼可以解決這個問題
popWindow.setTouchable(true); popWindow.setTouchInterceptor(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return false; // 這里如果返回true的話,touch事件將被攔截 // 攔截后 PopupWindow的onTouchEvent不被調用,這樣點擊外部區域無法dismiss } });