Use popupwindow in Android.
Popupwindow will block the dialog box, and you need to exit in the external thread or popupwindow itself.
The layout design of mypopwindow. XML is as follows.
<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Background = "#259" Android: orientation = "vertical"> <textview Android: Id = "@ + ID/textview1" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "here is pop window"/> <button Android: Id = "@ + ID/button1" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "OK"/> <button Android: Id = "@ + ID/button2" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "cancle"/> </linearlayout>
Mainactivity. Java file.
Click the button in mainactivity, and popupwindow is displayed.
private void showpopwindow (context, view parent) {layoutinflater Inflater = (layoutinflater) context. getsystemservice (context. layout_inflater_service); final view vpopwindow = Inflater. inflate (R. layout. mypopwindow, null, false); // 300 wide and 300 high final popupwindow popwindow = new popupwindow (vpopwindow, 300,300, true); button okbutton = (button) vpopwindow. findviewbyid (R. id. button1); okbutton. setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (view v) {// todo auto-generated method stubtoast. maketext (mainactivity. this, "you click OK", toast. length_short ). show () ;}}); button canclebutton = (button) vpopwindow. findviewbyid (R. id. button2); canclebutton. setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (view v) {// todo auto-generated method stubpopwindow. dismiss (); // close the pop window}); popwindow. showatlocation (parent, gravity. center, 0, 0) ;}
As shown in the following figure: It is shown in the end. Here I just cut some pictures.
Click OK to display your click OK information. Click Cancel to close the popupwindow.