Android overlay to grab ALL touch, and pass them on?

前端 未结 4 1614
我寻月下人不归
我寻月下人不归 2020-11-28 08:33

I\'m basically trying to get all touch event data from something like a system overlay, move my sprites around based on this touch data, then allow the OS/homescreen/browser

4条回答
  •  盖世英雄少女心
    2020-11-28 09:21

    I was looking for the same thing.

    This flag does the trick for me FLAG_NOT_TOUCH_MODAL

    Works on Android 7 and 8 setup as below.

    The only action I've implemented so far is a touch to close the overlay window.

    I also used code from here Example System Overlay Code on Github which was needed to get the events.

    By the way Google Maps does a really nice job with this on Android 8. You can drag their overlay window around, resize it or close it. And all other apps work fine while it's up.

        var type = 0
    
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        {
            type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
        }
        else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        {
            type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
        }
    
        var flags = FLAG_NOT_TOUCH_MODAL
    
        mOverlayLayoutParams = WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, type, flags, PixelFormat.TRANSLUCENT)
    

提交回复
热议问题