关于setShortcut

a220315410 2010-11-15 04:43:17
执行setShortcut('0','a');的效果应该是 点击0或者a都会激发MenuItem所对应的onOptionsItemSelected()吧?

但是为什么我每次执行的效果都是,点击a会执行onOptionsItemSelected(),而点击0则没有反应,这是为什么?
...全文
778 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
guolong2008 2012-07-03
  • 打赏
  • 举报
回复
楼主回答的有道理!
a220315410 2011-07-20
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 vanezkw 的回复:]

还好在你这里找到了解释。谢谢楼主
[/Quote]
呵呵,找到了就好~
vane 2011-07-20
  • 打赏
  • 举报
回复
还好在你这里找到了解释。谢谢楼主
jeky_zhang2013 2011-06-01
  • 打赏
  • 举报
回复
我在模拟器上也试了,只有字母可以~~
lsw20042008 2011-03-17
  • 打赏
  • 举报
回复
哈哈,我也遇到这个问题了,谢谢楼主的回答啊
aibin327 2011-03-10
  • 打赏
  • 举报
回复
Parameters
numericChar The numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard.
alphaChar The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.
纠结的木棉花 2010-11-16
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 a220315410 的回复:]

终于知道原因了。
setShortcut之所以要两个参数来设定两个快捷键是为了应对不同的手机键盘。
数字快捷键为12键键盘(0~9,*,#,共12个按键)所准备的。其实我怀疑有这种键盘的手机能装Android么?
因为我的键盘不是12键盘,所以数字快捷键是无法工作的。只有字母快捷键能够起效。
[/Quote]
原来真的..
a220315410 2010-11-16
  • 打赏
  • 举报
回复
终于知道原因了。
setShortcut之所以要两个参数来设定两个快捷键是为了应对不同的手机键盘。
数字快捷键为12键键盘(0~9,*,#,共12个按键)所准备的。其实我怀疑有这种键盘的手机能装Android么?
因为我的键盘不是12键盘,所以数字快捷键是无法工作的。只有字母快捷键能够起效。
a220315410 2010-11-16
  • 打赏
  • 举报
回复
恩,没关系。
谢谢你回复这个帖子。
纠结的木棉花 2010-11-16
  • 打赏
  • 举报
回复
数字键是不是也区分键盘呢?我不太清楚..这个
a220315410 2010-11-16
  • 打赏
  • 举报
回复
google提供的完整说明:
public abstract MenuItemsetShortcut(char numericChar, char alphaChar)
Since: API Level 1
Change both the numeric and alphabetic shortcut associated with this item. Note that the shortcut will be triggered when the key that generates the given character is pressed alone or along with with the alt key. Also note that case is not significant and that alphabetic shortcut characters will be displayed in lower case.
See Menu for the menu types that support shortcuts.
Parameters
numericChar The numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard.
alphaChar The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.
ReturnsThis Item so additional setters can be called.

也查了网上的资料,的确两个参数都是快捷键。

你可以使用setShortcut方法给菜单项指定快捷键。每一次调用setShortcut需要两个快捷键,一个是数字键,另一个可以是全键盘中的键。任何键不区分大小写。


下面的代码片段给出了如何为两种模式设定快捷键:


// Add a shortcut to this menu item, ‘0’ if using the numeric keypad

// or ‘b’ if using the full keyboard.

menuItem.setShortcut(‘0’, ‘b’);

但是为什么只有字母快捷键起效,就不知道了。
a220315410 2010-11-15
  • 打赏
  • 举报
回复
Change both the numeric and alphabetic shortcut associated with this item. Note that the shortcut will be triggered when the key that generates the given character is pressed alone or along with with the alt key. Also note that case is not significant and that alphabetic shortcut characters will be displayed in lower case.
See Menu for the menu types that support shortcuts.
Parameters
numericChar The numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard.
alphaChar The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.
ReturnsThis Item so additional setters can be called.

以上是Google提供的Reference。我的理解,两个参数都是快捷键
纠结的木棉花 2010-11-15
  • 打赏
  • 举报
回复
首先弄清楚setshortcut是干嘛用的:
设置快捷键和浮动说明文字

调用函数item的成员函数setShortcut(numericChar, alphaChar)
还有它的两个参数的意义...
a220315410 2010-11-15
  • 打赏
  • 举报
回复
在onCreateOptionsMenu函数中。
纠结的木棉花 2010-11-15
  • 打赏
  • 举报
回复
你的setShortcut是在哪儿用到的啊?

80,471

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧