PopupWindow - Dismiss when clicked outside

villager picture villager · Sep 2, 2012 · Viewed 86.4k times · Source

I have a PopupWindow on my activity, the thing is my PopupWindow still shows even when I'm interacting with my activity (say scrolling on my list). I can scroll through my list and the PopupWindow is still there.

What I want to achieve is when I'm touching/scrolling/clicking/etc on the screen which is not the PopupWindow, I want to dismiss the PopupWindow. Just like how a menu works. If you clicked outside of the menu, the menu will be dismissed.

I've tried setOutsideTouchable(true) but it won't dismiss the window. Thanks.

Answer

Marcin S. picture Marcin S. · Sep 2, 2012

Please try to set setBackgroundDrawable on PopupWindow that should close the window if you touch outside of it.