Skip to content

Instantly share code, notes, and snippets.

@jiemachina
Created September 17, 2012 09:23
Show Gist options
  • Save jiemachina/3736413 to your computer and use it in GitHub Desktop.
Save jiemachina/3736413 to your computer and use it in GitHub Desktop.
popuWindow 快速点击,背景透明
//背景不透明
mPopupWindow.setBackgroundDrawable(null);
final View contentView = getContentView();
//设置触摸事件 给 PopupWindow的ContentView重新设置触摸事件 解决setOutsideTouchable(true) 失效了,contentView为popuwindow的View
contentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int x = (int) event.getX();
final int y = (int) event.getY();
if ((event.getAction() == MotionEvent.ACTION_DOWN)
&& ((x < 0) || (x >= getWidth()) || (y < 0) || (y >= getHeight()))) {
dismiss();
return true;
} else if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
dismiss();
return true;
} else {
return contentView.onTouchEvent(event);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment