AlertDialog.Builder builder = new AlertDialog.Builder(this); TextVIEw Title = new TextVIEw(this); Title.setText("DM2"); Title.setBackgroundcolor(color.DKGRAY); Title.setpadding(10,10,10); Title.setGravity(Gravity.CENTER); Title.setTextcolor(color.WHITE); Title.setTextSize(20); TextVIEw text = new TextVIEw(this); text.setText("Hello This text"); text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); text.setTextSize(20); text.setGravity(Gravity.CENTER); //Creates a linearlayout layout and sets it with initial params linearLayout ll = new linearLayout(this); ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); ll.setGravity(Gravity.CENTER); ll.addVIEw(text); builder.setCustomTitle(Title); builder.setPositivebutton( "Ok",new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog,int ID) { dialog.dismiss(); } }); Dialog d = builder.setVIEw(ll).create(); //Fills up the entire Screen WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(d.getwindow().getAttributes()); lp.wIDth = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; d.show(); d.getwindow().setAttributes(lp);
但我希望对话框出现在中心对齐的位置.现在它显示在窗口的顶部.@H_301_5@我尝试使用lp.garvity = Gravity.center,但没有用.@H_301_5@如果设备方向改变,我需要再按ok按钮关闭对话框.如何解决这个问题?
提前致谢@H_301_5@普什帕
解决方法 我迟到了,但是迟到的时候再好不过了:-) @H_301_5@你可以使用下面的代码:(我也看到了 here)dialog = new Dialog(activity,androID.R.style.theme_Translucent_NoTitlebar);dialog.setContentVIEw(R.layout.activity_upload_photo_dialog);Window window = dialog.getwindow();window.setLayout(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);window.setGravity(Gravity.CENTER);//The below code is EXTRA - to dim the parent vIEw by 70%LayoutParams lp = window.getAttributes();lp.dimAmount = 0.7f;lp.flags = LayoutParams.FLAG_DIM_BEHIND;dialog.getwindow().setAttributes(lp);//Show the dialogdialog.show();
希望我帮忙……
总结以上是内存溢出为你收集整理的如何在android中对齐自定义对话框中心?全部内容,希望文章能够帮你解决如何在android中对齐自定义对话框中心?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)