Android: delegate touch event to underlaying view

前端 未结 3 778
旧时难觅i
旧时难觅i 2020-12-24 13:54

I have the following hierarchy: Activity -> PopupWindow -> CustomView

My the PopupWindow itself is a square, but

3条回答
  •  时光取名叫无心
    2020-12-24 14:24

    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);
    

提交回复
热议问题