Use the Settings dialog box to set the size, location, style, and settings on the Android desktop pop-up dialogs

Source: Internet
Author: User

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

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.