setShortcut

来源:互联网 发布:网络于技术流的意思 编辑:程序博客网 时间:2024/06/08 14:02

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
numericCharThe numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard.alphaCharThe 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所对应的对话框了



原创粉丝点击