Android keyEvent菜单键不起作用

时间:2015-07-26 14:13:21

标签: android keyevent

为什么这段代码对我不起作用?

我想在Android中为硬件菜单键设置onClickListener。请帮帮我。

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch(keyCode){
        case KeyEvent.KEYCODE_MENU:
            Toast.makeText(this, "Menu key pressed", Toast.LENGTH_SHORT).show();
            return true;

            return false;
    }
    return super.onKeyDown(keyCode, event);
}

1 个答案:

答案 0 :(得分:0)

不应该像

public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch(keyCode){
        case KeyEvent.KEYCODE_MENU:
            Toast.makeText(this, "Menu key pressed", Toast.LENGTH_SHORT).show();
            return true;

        default: return super.onKeyDown(keyCode, event);

}

}