alertDialog的底部显示

第一步创建alertdialog

  Alertdialog.builder builder=new AlertDialog.builder(this);

View view=layoutInflater.from(this).inflate(布局文件,null);

builder.setView(view);

AlertDialog   dialog=builder.creat();

 dialog.show();

以上就是显示AlertDialog的所用步骤

接下来就是底部显示的重要代码

 Window window = dialog.getWindow();
                window.setGravity(Gravity.BOTTOM);
                WindowManager m = getWindowManager();
                Display d = m.getDefaultDisplay(); //为获取屏幕宽、高
                WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); //获取对话框当前的参数值
                p.width = d.getWidth(); //宽度设置为屏幕
                dialog.getWindow().setAttributes(p); //设置生效

猜你喜欢

转载自blog.csdn.net/xukangone/article/details/80637235
今日推荐