Dialog Mydialog = new Dialog (this); Setcontentview can set the view can also be a layout file Mydialog.setcontentview (R.layout.test_akey); Window Dialogwindow = Mydialog.getwindow (); Windowmanager.layoutparams LP = Dialogwindow.getattributes (); Dialogwindow.setgravity (Gravity.left | Gravity.top); Gets the current window WindowManager mwindowmanager= (windowmanager) getapplication (). Getsystemservice (Getapplication (). Window_service); lp.x = 200; X-coordinate lp.y = 200; The y-coordinate (depending on the window size, for example, half of the height of the window mwindowmanager.getdefaultdisplay (). GetHeight ()/2) Lp.width = WindowManager.LayoutParams.WRAP _content; width lp.height = WindowManager.LayoutParams.WRAP_CONTENT; Height lp.alpha = 0.8f; Transparency////Click Elsewhere to disappear mydialog.setcancelable (true); Dialogwindow.setattributes (LP); Rewrite Onkeylistener, where you can intercept keystrokes Mydialog.setonkeylistener (new Onkeylistener () {@Override public boolean OnKey (dialoginterface Mydialog, int keycode, keyevent event) {if (keycode==keyevent.keycode_back) {//Intercept return key return true; } else return false; } }); Gets the control in Dialog button mtest_btn = (button) Mydialog.findviewbyid (R.ID.TEST_BTN); Mydialog.show ();//Display Dialog Mydialog.dismiss ();//Close Dialog
android dialog coordinate location, layout file, key blocker