Search code examples
androidandroid-2.3-gingerbreadandroid-windowmanager

How to make View in WindowManager intercept all the touches?


I have a little (100*100) View, that I added to WindowManager, and I want it to intercept all the touch events, including that are outside of this view. By default, touch outside this view is handled by view "behind" this view.


Solution

  • Use Activity's method dispatchTouchEvent

    Called to process touch screen events. You can override this to intercept all touch screen events before they are dispatched to the window. Be sure to call this implementation for touch screen events that should be handled normally.

    This code will let your little view intercept all touch events.

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return littleView.onTouchEvent(ev);
    }