Created
September 17, 2012 09:23
-
-
Save jiemachina/3736413 to your computer and use it in GitHub Desktop.
popuWindow 快速点击,背景透明
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//背景不透明 | |
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