android dialog full-screen, activity-sized settings detailed

Source: Internet
Author: User

Introduction: The dialog system by default is not allowed full screen, the following we introduce several dialog full-screen way


First

Final Dialog Dialog = new Dialog (wendetailactivity.this, r.style.popupdialog);        Dialog.requestwindowfeature (window.feature_no_title);        Dialog.setcontentview (R.layout.wen_cover_pager);        Dialog.setcanceledontouchoutside (false);        Dialog.setcancelable (False);d ialog.show ();


Style:

<span style= "FONT-SIZE:14PX;" ><style name= "Popupdialog" parent= "@android: Style/theme.light.notitlebar.fullscreen" > <item name= "android Oid:windowbackground "> @drawable/filled_activity_bg</item> <item name=" android:backgrounddimenabled "& gt;false</item> <item name= "android:windowisfloating" >true</item> <item name= "android:w  Indowistranslucent ">true</item> <item name=" Android:windownotitle ">true</item> <item Name= "Android:windowcontentoverlay" > @null </item> <!--<item name= "Android:windowanimationstyle" > @style/dialog_animation</item>--> <item name= "Android:colorbackgroundcachehint" > @null </ item> <item name= "Android:backgrounddimamount" >0.6</item><!--Grayscale--<item name= "and Roid:windowfullscreen ">true</item> </style></span> 

Second

We can also customize dialog, inherit Dialig first, and then add the constructor

Super (context, Android. R.style.theme);
Setowneractivity (Activity) context);


Third

Or we set://dialog.getwindow (). setlayout (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT );

Also allows our dialog to be displayed in full screen.


Note: Set dialog fullscreen as described above, some friends may find that dialog fullscreen is not what we want, because it also obscures the status bar, sometimes we just want it to cover the title bar, is the same size as our activity, In this case, the following small series describes a way to set the size of dialog and activity.


Third

First introduce a method: Getdecorview ()

Decorview is the topmost view in window, you can get to decorview from window, and Decorview has a getwindowvisibledisplayframe method to get to the area displayed by the program, including the title bar , but does not include the status bar.
So we can figure out the height of the status bar.

        Rect frame = new Rect ();        GetWindow (). Getdecorview (). Getwindowvisibledisplayframe (frame);        int statusbarheight = Frame.top;
Also we get the height of the title bar

GetWindow (). Findviewbyid (Window.id_android_content) This method gets to the view that the program does not include the title bar of the section, and then you can know the height of the title bar, the code is as follows:

int contenttop = GetWindow (). Findviewbyid (window.id_android_content). GetTop ();
int titlebarheight = Contenttop-statusbarheight; //statusbarheight is the height of the status bar that is asked above

Finally: Knowing the above principles, we can set our dialog as large as the activity, the Java code is as follows:

Final Dialog Dialog = new Dialog (wendetailactivity.this, r.style.popupdialog);        Dialog.requestwindowfeature (window.feature_no_title);        Dialog.setcontentview (R.layout.wen_cover_pager);        Dialog.setcanceledontouchoutside (false);        Dialog.setcancelable (false);        Windowmanager.layoutparams lay = Dialog.getwindow (). GetAttributes ();        Displaymetrics dm = new Displaymetrics ();        Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);        Rect rect = new rect ();        View view = GetWindow (). Getdecorview ();//decorview is the topmost view in window and can be obtained from the window Decorview        View.getwindowvisibledisplayframe (rect);        Lay.height = Dm.heightpixels-rect.top;        Lay.width = Dm.widthpixels;
Style.xml as follows:

<style name= "Popupdialog" parent= "@android: Style/theme.dialog" >        <item name= "Android:windowbackground "> @drawable/filled_activity_bg</item>        <item name=" android:backgrounddimenabled ">false</ item>        <item name= "android:windowisfloating" >true</item>        <item name= "Android: Windowistranslucent ">true</item>        <item name=" Android:windownotitle ">true</item>        <item name= "Android:windowcontentoverlay" > @null </item>        <!--<item name= "Android: Windowanimationstyle "> @style/dialog_animation</item>-->        <item name=" Android: Colorbackgroundcachehint "> @null </item>        <item name=" Android:backgrounddimamount ">0.6</item ><!--Grayscale--        <!--<item name= "Android:windowfullscreen" >true</item>-->    </ Style>






android dialog full-screen, activity-sized settings detailed

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.