Reputation: 9326
I have a PopupWindow with a Close-Button, and I only want to close the PopupWindow when this Close-Button is clicked. In addition, I don't want to underlying Activity-View to be affected by any touches.
This has been asked before: Android Popup Window dismisses when clicked outside. But since it's a question and answer of three years ago (2011) I was wondering if there is a better solution for this now or I should indeed use the accepted answer's method.
Upvotes: 2
Views: 6262
Reputation: 40810
You need to do both:
popupWindow.setOutsideTouchable(false);
popupWindow.setFocusable(false);
Check this out
Upvotes: 3
Reputation: 1803
try this link OR one of the below code
pw.setOutsideTouchable(false);
OR
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Rect dialogBounds = new Rect();
getWindow().getDecorView().getHitRect(dialogBounds);
if (!dialogBounds.contains((int) ev.getX(), (int) ev.getY())) {
// Tapped outside so we finish the activity
this.finish();
}
return super.dispatchTouchEvent(ev);
}
Hope this helps...
Upvotes: 0