AlertDialog弹窗在屏幕底部

监听按钮:R.id.imageView_saofeng:

LayoutInflater factory = LayoutInflater.from(SmartACActivity.this);
View myView = factory.inflate(R.layout.select_windy_speed,null);
myView.setPadding(10, 10, 10, 30);
Dialog dialog = new AlertDialog.Builder(SmartACActivity.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); //设置生效

你可能感兴趣的:(Android)