修改dialog的大小
16lz
2021-01-23
1.在manifest.xml中activity添加
android:theme="@android:style/Theme.Dialog"
2.WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay(); //为获取屏幕宽、高
LayoutParams p = getWindow().getAttributes(); //获取对话框当前的参数值
p.height = (int) (d.getHeight() * 0.6); //高度设置为屏幕的0.6
p.width = (int) (d.getWidth() * 0.95); //宽度设置为屏幕的0.95
getWindow().setAttributes(p); //设置生效
android:theme="@android:style/Theme.Dialog"
2.WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay(); //为获取屏幕宽、高
LayoutParams p = getWindow().getAttributes(); //获取对话框当前的参数值
p.height = (int) (d.getHeight() * 0.6); //高度设置为屏幕的0.6
p.width = (int) (d.getWidth() * 0.95); //宽度设置为屏幕的0.95
getWindow().setAttributes(p); //设置生效