dialog display in different locations of activity

Source: Internet
Author: User

dialog is displayed by default in the middle, to be displayed in other locations, use the following method to implement

private void ShowDialog () {
Alertdialog Mdialog = new Alertdialog.builder (this)
. SetIcon (R.drawable.ic_launcher). Settitle ("Warm Tips")
. Setmessage ("Transparent dialog box")
. Setpositivebutton ("OK", null). Create ();
Gets the Window object of the dialog box
Window Mwindow = Mdialog.getwindow ();
Windowmanager.layoutparams LP = Mwindow.getattributes ();
The scope of transparency is: 0.0f-1.0f;0.0f is completely transparent and 1.0f is completely opaque (this is the default for the system).
Lp.alpha = 0.35f;
The settings dialog is displayed at the bottom of the screen and, of course, up or down, anywhere
Mwindow.setgravity (Gravity.left);
Mwindow.setgravity (Gravity.bottom);
/*
*
* Here is the set offset, where x, Y is not relative to the absolute coordinates of the screen, but rather relative to the dialog box in the center position (the default dialog box is generally displayed in the center of the screen)
lp.x = -20;//Set Horizontal offset
LP.Y = -90;//Set vertical offset
*/
Set Properties for Window
Mwindow.setattributes (LP);

Mdialog.show ();
}

dialog display in different locations of activity

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.