DiaLog在底部显示

           LayoutInflater factory = LayoutInflater.from(MainActivity.this);
                View myView = factory.inflate(R.layout.item,null);
                myView.setPadding(10, 10, 10, 30);
                Dialog dialog = new AlertDialog.Builder(MainActivity.this)
                        .setView(myView).create();

//设置点击Dialog外部任意区域关闭Dialog
                dialog.setCanceledOnTouchOutside(true);

                dialog.show();
                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); //设置生效

你可能感兴趣的:(DiaLog在底部显示)