First step: Create a dialog box
Mydialog mydlg=new Mydialog (context);
Step two: Get the window Instance of the dialog box, control the location, size and pop-up scene of the dialog box through the window instance.
Window Dlgwindow=mydly.getwindow ();
Setting the final display location of the dialog box
Dlgwindow.setgravity (Gravity.top);
The parameters can be gravity.top (top),Gravity.button (bottom),gravity.left (left),Gravity.right (right) , Gravity.center (centered) and their combination
Setting the dialog box size
By getting the size of the screen, it's easier to set it up in proportional ways
First Get WindowManager instance
WindowManager m = (WindowManager) getsystemservice (Context.window_service);
Display d = m.getdefaultdisplay (); Get screen width, Gao Yun
Windowmanager.layoutparams p = dlgwindow.getattributes (); Gets the current parameter value of the dialog box
P.height = (int) (D.getheight () * 0.5); Height set to 0.5 of the screen
P.width = (int) (D.getwidth () * 1); Width set to entire screen width
P.alpha = 0.5f; Set the transparency of a dialog box
Dlgwindow.setattributes (P);//
The Settings dialog box pops up on the desktop
Mydlg.getwindow (). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);//Set up here to display the dialog box in the desktop
Sets the style of the window;
Styling a dialog box with a style file
Here are some of the most commonly used tags
<item name= "Android:windowfullscreen" >true</item> <!--fill Screen--
<item name= "Android:windowframe" > @null </item>: Dialog windowframe box is not
<item name= "Android:windowisfloating" >TRUE</ITEM>: Whether it appears on the activity
<item name= "Android:windowistranslucent" >FALSE</ITEM>: Translucent
<item name= "Android:windownotitle" >TRUE</ITEM>: whether the title is displayed
<item name= "Android:windowbackground" > @drawable/dia_bg</item>: Setting dialog background
<item name= "android:backgrounddimenabled" >FALSE</ITEM>: whether the background is blurry or not
<item name= "Android:windowanimationstyle" > @style/xxx_ani</item>: Setting Popup and Vanishing animations for dialog boxes
Other:
Set the click outside of the dialog box to close the dialog box
Mydlg.setcanceledontouchoutside (TRUE);
Animate animated Settings
Mydlg.getwindow (). Setwindowanimations (R.style.dialog_ani);
How to set a style for a dialog box
If you are using the inherit dialog from the Customize dialog box, set through the constructor
Eg:super (Context,r.style.mydialog);
Use the Settings dialog box to set the size, location, style, and settings on the Android desktop pop-up dialogs