popupwindow 捕获不到 setTouchInterceptor

红色的是关键两句。



PopupWindow window;

View v = this.getLayoutInflater().inflate(R.layout.popupwindow, null);

window = new PopupWindow(v, 200, 300);



 window.setOutsideTouchable(true);;//这里设置显示PopuWindow之后在外面点击是否有效。如果为false的话,那么点击PopuWindow外面并不会关闭PopuWindow。当然这里很明显只能在Touchable下才能使用。不设置此项则下面的捕获window外touch事件就无法触发。


  变态

  Drawable win_bg = this.getResources().getDrawable(R.drawable.bg);

  window.setBackgroundDrawable(win_bg);

  这个很,即使在XML里设置了background也认为是没有背景,必须在这里指定背景,如果不指定同样无法触发下面的Touch监听事件。

  window.setTouchInterceptor(new OnTouchListener() {

  @Override

  public boolean onTouch(View v, MotionEvent event) {

  if (event.getAction() == MotionEvent.ACTION_OUTSIDE)

  window.dismiss();

  return false;

  }

  });

你可能感兴趣的:(popupwindow 捕获不到 setTouchInterceptor)