1.問題描述
AlertDialog在同事9.0.0的手機(jī)上不居中顯示殖妇,處于屏幕偏右。
2.解決方案
添加以下代碼:
AlertDialog dialog = builder.create();
dialog.show();
Window dialogWindow = dialog.getWindow();
WindowManager m =activity.getWindowManager();
Display d = m.getDefaultDisplay();
WindowManager.LayoutParams p = dialogWindow.getAttributes();
p.width = (int) (d.getWidth() *0.95);
p.gravity = Gravity.CENTER;
dialogWindow.setAttributes(p);