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