Private Popupwindow Mpopupwindow; // The popup window generally popuowindow to show the view, in this case the view simulation menu. Private View Mmenu; // the view in the popup window
Scenario 1:
Mmenu.setfocusableintouchmode (TRUE);
Mmenu.setonkeylistener (this);
Mmenu.setontouchlistener (this);
Mpopupwindow.setfocusable (TRUE);
Mpopupwindow.setoutsidetouchable (TRUE);
@Override Public BooleanOnKey (View V,intKeyCode, KeyEvent event) { //TODO auto-generated Method Stub Switch(keycode) { CaseKeyevent.keycode_back: CaseKeyevent.keycode_menu:if(Mpopupwindow! =NULL&&mpopupwindow.isshowing ()) {Mpopupwindow.dismiss (); } Break; } return true; } @Override Public BooleanOnTouch (View V, motionevent event) {//TODO auto-generated Method StubMpopupwindow.dismiss (); return false; }
Scenario 2:
/ * * Setbackgrounddrawable is very important, without this function back key and the menu key to close Popwindow very troublesome, * with it later, You do not have to set Setonkeylistener and Setontouchlistener for the controls within the Popwindow * can support back,menu keys and point Popwindow outside the Popwindow, * /mpopupwindow.setbackgrounddrawable (new colordrawable ( -00000)); Mpopupwindow.setfocusable (true); Mpopupwindow.setoutsidetouchable (true);
Popupwindow (3) Back,home key cannot turn off solution for Popupwindow