1.style 设置:
<style name="dialog_activity_style" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
2.AndroidManifest.xml 设置:
<activity
android:name=".SecondActivity"
android:theme="@style/dialog_activity_style"/>
3.动态设置窗口大小:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setDisplay();
}
//设置窗口大小
private void setDisplay() {
DisplayMetrics dm = new DisplayMetrics();
getWindow().getWindowManager().getDefaultDisplay().getMetrics(dm);
WindowManager.LayoutParams p = getWindow().getAttributes();
p.height =(int) (dm.heightPixels * 0.8);
p.width = (int) (dm.widthPixels * 0.8);
getWindow().setAttributes(p);
}