Questions about the width of the android dialog box cannot be covered full screen

Source: Internet
Author: User

This is basically the case when you need to make a custom dialog box with a width full screen.

Alertdialog dialog = new Alertdialog.builder (context). Create ();        Dialog.show ();        window window = Dialog.getwindow ();        Windowmanager.layoutparams LP = Window.getattributes ();        Lp.width = WindowManager.LayoutParams.MATCH_PARENT;        Window.setattributes (LP); Window.setwindowanimations (R.style.dialogwindowanim);//Animation Window.setcontentview (R.layout.layout_mine_bank_del) ;//Layout window.setgravity (Gravity.center);

I've never had a problem before, and I didn't use it until this time.

"Apptheme.noactionbar"

Theme, at more than 5.0 mobile phones found the width can not be covered; If you set the location at the bottom

Window.setgravity (Gravity.bottom);

There is also a distance at the bottom.

Very depressed, tried the other way:

Window.getdecorview (). setpadding (0, 0, 0, 0);

Or

Window.setlayout (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

Or

window window = GetWindow (); Windowmanager.layoutparams WLP = window.getattributes ();D isplay d = Window.getwindowmanager (). GetDefaultDisplay ();// Gets the screen width wlp.width = (int) (D.getwidth ());//width is set;d as a percentage of the screen size. GetWidth () This method has been discarded wlp.gravity = gravity.center; Window.setattributes (WLP);

But they have not been able to succeed. Until today, I accidentally saw this in a blog to solve the problem.

Window.setbackgrounddrawableresource (Android. R.color.transparent);

Add this sentence to the no problem, haha!

Thank you, Bo Lord http://blog.csdn.net/bear_huangzhen/article/details/51683758


By the way, just like that, the custom dialog box needs to first

Dialog.show ();

It's OK, or it'll go wrong. Another way to customize through inheritance is to show the last face.

public class Mydialog extends alertdialog{public mydialog (context context) {super (context);       } @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);    This.setcontentview (R.layout.my_dialog); }}

This kind of use is also relatively simple, flexibility or

Final Mydialog Mydialog = new Mydialog (context); Mydialog.setmsg ("Test Show custom Dialog box"); Mydialog.setonpositivelistener ("Know",    New View.onclicklistener () {@Override public void OnClick (View v) {mydialog.cancel (); }}); Mydialog.show ();


This article is from the "Fly to learn Android" blog, please be sure to keep this source http://qq445493481.blog.51cto.com/9545543/1790387

Questions about the width of the android dialog box cannot be covered full screen

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.