记录一个Dialog的创建,方便获取
创建
//创建
Dialog dialog = new Dialog(this, R.style.Translucent_NoTitle);
//设置自定义布局
View rootView = LayoutInflater.from(this).inflate(R.layout.activity_login, null, false);
dialog.setContentView(rootView);
//点击外部消失
dialog.setCanceledOnTouchOutside(true);
// 设置宽高及位置
Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.CENTER;
float density = getResources().getDisplayMetrics().density;
int width = (int) (150*density);
int height = (int) (100*density);
wlp.width = width;
wlp.height = height;
window.setAttributes(wlp);
//弹出
dialog.show();
样式
<style name="Translucent_NoTitle" parent="android:style/Theme.Dialog">
<!--去除标题-->
<item name="android:windowNoTitle">true</item>
<!--设置dialog的背景,它会被自定义的布局背景覆盖-->
<item name="android:background">@android:color/transparent</item>
<!--window的背景,设置之后可去除dialog的黑边-->
<item name="android:windowBackground">@android:color/transparent</item>
<!--设置之后可去除dialog的灰色半透明背景!!!!!-->
<item name="android:backgroundDimAmount">0</item>
</style>
|