实现对话框风格的activity,我们需要在AndroidManifest.xml添加一句样式声明:
<activity
android:name=".product.MyselfPayProduct"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Dialog" >
控制对话框大小(即activity宽高)
//窗口对齐屏幕宽度
Window win = this.getWindow();
win.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = win.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = (int) (getWindowManager().getDefaultDisplay().getHeight() * 0.7);
lp.gravity = Gravity.BOTTOM;//设置对话框置顶显示
win.setAttributes(lp);
---
WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay(); //为获取屏幕宽、高
WindowManager.LayoutParams p = getWindow().getAttributes(); //获取对话框当前的参数值
p.height = (int) (d.getHeight() * 1.0); //高度设置为屏幕的1.0---去除titlebar高度
p.width = (int) (d.getWidth() * 0.7); //宽度设置为屏幕的0.8
p.alpha = 1.0f; //设置本身透明度
p.dimAmount = 0.0f; //设置黑暗度
getWindow().setAttributes(p);
网友评论