Android 触摸屏事件的选择性消耗/传递

发布于 2025-01-03 00:30:32 字数 353 浏览 1 评论 0原文

我有一个基本上透明的 Android 活动,很像吐司。然而,它与吐司的不同之处在于,它在显示时可以进行交互,例如它提供了一个可以按下的按钮。

我想做的是 catch &使用 UI 显示区域内的触摸屏输入,并将其他所有内容传递给下面发生的任何活动(可能不是我的应用程序)。

显然两者皆有可能,但这种选择性模型可能吗?

这在其他 UI 语言中很常见,但我怀疑模型不允许这样做,特别是选择性接受事件以避免进一步处理。

到目前为止,我已经了解了 WindowManager.LayoutParams flags &类型,但我什至无法进入所有输入都发送到底层活动的状态(按照祝酒词)。

任何想法将不胜感激。

I have an Android activity that is largely transparent, much like a toast. However it is different from a toast in that while shown, it can be interacted with, e.g. it offers a button you can press.

What I would like to do is catch & consume touchscreen input within the display area of my UI, and pass everything else to whatever activity happens to be beneath (which may not be my app).

It's obviously possible to have one or the other, but is this selective model possible?

This is common in other UI languages but I suspect that this, in particular the selective accept of an event to avoid further processing, is not permitted by the model.

So far I've had a look at WindowManager.LayoutParams flags & types, but I can't even get into a state where all input is sent to underlying activities (as per a toast).

Any thoughts would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱本泡沫多脆弱 2025-01-10 00:30:32

事实证明这是可能的,答案大致可以在 这个问题

一个关键点是,这是一项服务,并且相同的方法不适用于活动 - 因为它本质上是底层活动,即使是透明的(废话)。 onTouch(...) 方法返回的布尔结果允许您有选择地使用事件的处理。

我还没有研究这对视图构建有何影响,因为这对我来说是一个缓慢燃烧的问题。

It transpires that this is possible, and the answer is broadly as found in this SO question.

One key point is that this is a service, and the same approach does not work from an activity - because it is inherently the underlying activity even when transparent (duh). The boolean result returned by the onTouch(...) method allows you to selectively consume handling of the event.

I haven't looked at what implications this has for view construction yet, because this is a slow burning issue for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文