我在試着測試PopupWindow類。我創建這個方法來顯示彈出:PopupWindow TouchInterceptor不能正常工作
public void showPopup(){
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popup = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
popup.setOutsideTouchable(true);
popup.setTouchable(true);
popup.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("POPUP", event.toString());
if(event.getAction() == MotionEvent.ACTION_OUTSIDE){
popup.dismiss();
return true;
}
return true;
}
});
popup.showAtLocation(findViewById(R.id.main), Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 200);
}
彈出正確顯示,順便似乎觸摸攔截沒有在所有的工作:我沒有得到任何的日誌信息和當然,彈出窗口如果在窗口之外按下,它並不會被解僱。
是否有一些進一步的屬性,我必須在彈出窗口或活動主機中設置?
我有這個相同的問題,讓我記得我是如何修復它。 – a54studio 2013-03-22 12:53:35