Search code examples
androidpopupwindowandroid-menu

PopupWindow - Dismiss when clicked outside


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.


Solution

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