Pass through touch events on window overlay to an Activity behind it

荒凉一梦 提交于 2019-12-06 07:05:20

问题


Some context.
I have a RelativeLayout that is added with a WindowManager the type is TYPE_SISTEM_ALERT with the flags FLAG_NOT_TOUCH_MODAL FLAG_WATCH_OUTSIDE_TOUCH.
I'm able to get touch events either on this RelativeLayout or in the Activity "behind" it, but as long as it's not part of the "RelativeLayout window" added.

* The black bars are the Views on my RelativeLayout;
* the red rectangle is the whole container of this RelativeLayout;
* the yellow stars are the spots of space that is created from the black views;
* the white space is the Activity behind this RelativeLayout window on top.

Imagine there is a Button on the yellow stars spots that are from the Activity A, BUT are VISIBLE to the user and if he clicks there.
the Button of the Activity A should be able to respond, even though its "behind" this RelativeLayout Window.

My references, but unfortunately without success so far are :

  1. Android overlay to grab ALL touch, and pass them on?
  2. Android : Multi touch and TYPE_SYSTEM_OVERLAY

Is there a workaround to this?


回答1:


Is there a workaround to this?

If the activity in question is your own activity, get rid of the system-level overlay and implement the overlay in your activity's own view hierarchy.

If the activity in question is not your own activity, then AFAIK what you want is not possible. Windows in Android, at the moment at least, are purely rectangular; I know of no way that you can set up your window to be non-rectangular and have the activity truly be the top-most item in those transparent areas. And, passing touch events along has been blocked since Android 4.0, for security reasons (tapjacking attacks).



来源:https://stackoverflow.com/questions/33697384/pass-through-touch-events-on-window-overlay-to-an-activity-behind-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!