android window弹出窗
2018-01-23 本文已影响0人
神情自若
Dialog myDialog = new Dialog(MainActivity.this, R.style.Translucent_NoTitle);
View view = LayoutInflater.from(MainActivity.this).inflate(
R.layout.dialog, null);
myDialog.setContentView(view);
myDialog.setCanceledOnTouchOutside(true);
Window dialogWindow = myDialog.getWindow();
dialogWindow.setGravity(Gravity.CENTER);
//获取屏幕的宽高
WindowManager wm = this.getWindowManager();
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
//设置弹出框的大小
dialogWindow.setLayout(width*5/6,height/3);
//展示弹出
myDialog.show();
<!-- 弹窗风格-->
<style name="Translucent_NoTitle" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>