I have the following hierarchy: Activity
-> PopupWindow
-> CustomView
My the PopupWindow
itself is a square, but
It's too bad that the PopupWindow is not a subclass of ViewGroup or even View. Then you could override dispatchTouchEvent. Can you modify your custom view to know about the PopupWindow and call dismiss() on it when there is a click outside the circle?
Try setting these on your PopupWindow instance:
window.setBackgroundDrawable(new BitmapDrawable());
window.setOutsideTouchable(true);
and
window.setTouchable(true);
This is just a suggestion... I haven't tested it. Let me know if it works.
[Note: This is for the onTouch() to get called on touch events..]
Consider the FLAG_NOT_TOUCH_MODAL:
/** Window flag: Even when this window is focusable (its
* {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events
* outside of the window to be sent to the windows behind it. Otherwise
* it will consume all pointer events itself, regardless of whether they
* are inside of the window. */
public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020;
You can use this code to upate the window flags after the popup window was shown.
FrameLayout popupContainer = (FrameLayout)contentView.getParent();
WindowManager.LayoutParams p = (WindowManager.LayoutParams)popupContainer.getLayoutParams();
p.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
WindowManager windowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
windowManager.updateViewLayout(popupContainer, p);