如何在双击时创建上下文菜单?
我需要在双击和长按时创建上下文菜单。怎样才能做到呢?
我的意思是,通常当用户长按小部件时调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您需要将上下文相关的操作绑定到
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 theEditText
, with a downward-facing arrowhead (akin to aSpinner
), and tie thatImageButton
to aPopupMenu
(ideal, but only API Level 11), aPopupWindow
, or anAlertDialog
. Or, in a pinch, have theImageButton
display a context menu when clicked viashowContextMenu()
. 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).