setShortcut

http://developer.android.com/reference/android/view/MenuItem.html#setShortcut(char, char)

public abstract MenuItem setShortcut (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.
Returns
  • This Item so additional setters can be called.

 menu.add(0, MENU_ITEM_INSERT, 0, R.string.menu_insert)
                .setShortcut('3', 'a')
                .setIcon(android.R.drawable.ic_menu_add);

《 转》

MenuItem android.view. MenuItem.setShortcut(char numericChar, char alphaChar);
你可以使用setShortcut方法给菜单项指定快捷键。
每一次调用setShortcut需要两个快捷键,一个是数字键,另一个可以是全键盘中的键。任何键不区分大小写。
两个参数来设定两个快捷键是为了应对不同的手机键盘。
第一个参数:数字快捷键为12键键盘(0~9,*,#,共12个按键)
第二个参数:全键盘
MenuItem android.view. MenuItem.setIcon(int iconRes);
这个就是明显的设置MenuItem图标的问题了。


在android 的demo里面 有个绘图的程序,按下menu会弹出五个按钮
其设置如下:

  menu.add(0, COLOR_MENU_ID, 0, "Color").setShortcut('3', 'c');
        menu.add(0, EMBOSS_MENU_ID, 0, "Emboss").setShortcut('4', 's');
        menu.add(0, BLUR_MENU_ID, 0, "Blur").setShortcut('5', 'z');
        menu.add(0, ERASE_MENU_ID, 0, "Erase").setShortcut('5', 'z');
        menu.add(0, SRCATOP_MENU_ID, 0, "SrcATop").setShortcut('5', 'z');

查理相关资料后得出结论:

 setShortcut之所以要两个参数来设定两个快捷键是为了应对不同的手机键盘。
数字快捷键为12键键盘(0~9,*,#,共12个按键)所准备的。因为我的键盘不是12键盘,所以数字快捷键是无法工作的。只有字母快捷键能够起效。即当按下menu时候在按下c就能弹出color所对应的对话框了



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值