Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to consume and dismiss the PopupWindow when clicked outside?

Tags:

android

dialog

I'm currently designing simple tips popups using the PopupWindow class. I'm able to dismiss the popup when clicked outside of the content. However the touch events outside are consumed by the underlining layout. How can I consume the outside touches so that when clicked outside I still have the popup dismissed but there are no touch events being sent to the layout below my PopupWindow?

Current set properties:

mPopupWindow.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.popup_bg));
mPopupWindow.setOutsideTouchable(true);
like image 206
Jona Avatar asked Jan 11 '12 17:01

Jona


2 Answers

Turns out there is a way to do it! After looking deep into PopupWindow and ListPopupWindow I discovered the option setFocusable(true); will do exactly what I needed!

like image 68
Jona Avatar answered Oct 05 '22 19:10

Jona


If you are using ListPopupWindow then setModal(true) will do the trick.

like image 42
klemzy Avatar answered Oct 05 '22 20:10

klemzy