dismiss popup when options menu is pressed
问题 I implemented a popup which shows up when I press the hardware menu key. Now I want to dismiss the popup when I press on the menu key again. I tried this @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU) { if (pw.isShowing()) { pw.dismiss(); } else { openpopup(); } return true; } return super.onKeyDown(keyCode, event); } here's the open popup method public void openpop() { View view1 = getCurrentFocus(); showpopup(view1); } here's the