首页 > 代码库 > AlertDialog 自定义大小

AlertDialog 自定义大小

AlertDialog salert = new AlertDialog.Builder(this).create(); 
salert.show(); 
//******************改变alertdialog 
Window dialogWindow = salert.getWindow();

dialogWindow.setGravity(Gravity.RIGHT | Gravity.TOP);
WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
p.height = (int) (d.getHeight() * 0.125); // 高度设置为屏幕的0.6
p.width = (int) (d.getWidth() * 0.4); // 宽度设置为屏幕的0.65
p.y=100;
dialogWindow.setAttributes(p);

salert.getWindow().setContentView(R.layout.settings_items);

 

salert.show(); 必须写前面!

 

AlertDialog 自定义大小