如何在双击时创建上下文菜单?

发布于 2024-11-18 01:58:01 字数 233 浏览 4 评论 0原文

我需要在双击和长按时创建上下文菜单。怎样才能做到呢?

我的意思是,通常当用户长按小部件时调用 onCreateContextMenu 。就我而言,当用户双击小部件时,我需要执行相同的操作。

添加

我知道这不是一个很好的选择,因为它对于 Android UI 来说并不正常。但我的主要问题是解决一些供应商的设备的 UI 错误 - 即 HTC (

I need to create context menu on double click as well as on long tapping. How it can be done?

I mean normally onCreateContextMenu called when user press long tap on widget. In my case I need to do the same when user double clicks on widget.

ADDED

I know that it's not really nice option, since it's not normal for Android UI. But my primary problem is to solve UI bugs for devices of some vendors - namely HTC (look this post). I have seemingly resolved described issue, but still I do have problems with context menus. So as a last resort I just thought to avoid tapping through double click. Thanx for understanding...

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

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

发布评论

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

评论(1

眼眸印温柔 2024-11-25 01:58:01

据我所知,您需要将上下文相关的操作绑定到 EditText,而 HTC 对 Android 的更改会干扰这一点。

首先,我会重新考虑一般情况下使用上下文菜单,因为它们不是特别容易发现,因此大多数用户永远不会找到它们。

其次,就 EditText 而言,用户发现双击会弹出上下文菜单的几率与地球遭受灭绝级小行星撞击的几率相当今天。

:: 仰视天空 ::

一种选择是在 EditText 旁边放置一个小 ImageButton,并带有一个向下的箭头(而不是双击)类似于 Spinner),并将该 ImageButton 绑定到 PopupMenu (理想,但仅限 API 级别 11),一个 PopupWindow< /代码>,或一个AlertDialog。或者,在紧要关头,通过 showContextMenu() 单击时让 ImageButton 显示上下文菜单。这也是非标准的用户体验,但它至少更容易被发现,因为用户会习惯在 Android 和其他操作系统中按下向下箭头按钮时弹出的内容。

如果您绝对确信需要双击,据我所知,这不是可识别的触摸事件,因此您需要自己处理低级触摸事件,确定何时发生双击,并以某种方式执行此操作这不会干扰 EditText 的使用(例如,设置光标位置)。

From what I gather, you have context-sensitive actions you want tied to an EditText, and HTC's changes to Android are interfering with that.

First, I would reconsider using context menus in general, as they are not particularly discoverable, so most of your users will never find them.

Second, in the case of the EditText, the odds of users discovering that a double-tap will bring up a context menu will be on par with the odds that the Earth will have an extinction-level asteroid strike today.

:: looks up in sky ::

Rather than a double-tap, one option would be to put a small ImageButton adjacent to the EditText, with a downward-facing arrowhead (akin to a Spinner), and tie that ImageButton to a PopupMenu (ideal, but only API Level 11), a PopupWindow, or an AlertDialog. Or, in a pinch, have the ImageButton display a context menu when clicked via showContextMenu(). This too is non-standard UX, but it is at least more discoverable, as users will be used to things popping up when pressing down-arrow buttons, from both Android and other OSes.

If you are absolutely convinced that you need a double-tap, AFAIK that is not a recognized touch event, so you will need to handle the low-level touch events yourself, determine when a double-tap occurs, and do so in a way that does not interfere with the usage of the EditText (e.g., setting cursor position).

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