为什么这段代码对我不起作用?
我想在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);
}
答案 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);
}
}