Android implementation of the Floating dialog box code _android

Source: Internet
Author: User

First show you the effect of the map, we feel satisfied with the results, please refer to the implementation code.

Directly on the code:

private void Setdialog () {View view = Getlayoutinflater (). Inflate (r.layout.dialog_country, null); mdialog = New Dialog (th
IS);
Mdialog.setcontentview (view, New Layoutparams (Layoutparams.fill_parent, layoutparams.wrap_content));
window window = Mdialog.getwindow ();
Windowmanager.layoutparams wl = Window.getattributes ();
wl.x = 0;
Wl.y = Getwindowmanager (). Getdefaultdisplay (). GetHeight ();
Wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
Wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
Mdialog.onwindowattributeschanged (WL);
Mdialog.setcanceledontouchoutside (TRUE);
Mdialog.show ();
Button Btnchina = (button) View.findviewbyid (R.id.btnchina);
Button Btnusa = (button) View.findviewbyid (R.ID.BTNUSA);
Button Btnuk = (button) View.findviewbyid (R.id.btnuk);
Button Btncancel = (button) View.findviewbyid (R.id.btncancel); Btnchina.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {//TODO auto-generated method s Tub Mquery.id (r.id.btncountry). Gettextview (). SetText ("");
Mdialog.dismiss ();
} 
}); Btnusa.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {//TODO auto-generated method Stu
b mquery.id (r.id.btncountry). Gettextview (). SetText ("USA");
Mdialog.dismiss ();
} 
}); 
Btnuk.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {//TODO auto-generated method stub
Mquery.id (r.id.btncountry). Gettextview (). SetText ("UK");
Mdialog.dismiss ();
} 
});  Btncancel.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {//TODO auto-generated method
Stub Mdialog.dismiss ();
} 
}); }

The

First inflate an XML file, produces a view, creates a dialog, sets dialog view as Inflate view, and then sets the length of Windowmanager.layoutparams by Dialog, width, display position, and so on, finally Setcanceledontouchoutside (true), click Elsewhere to exit dialog.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.