1. Set the screen height and width.
// The window is aligned to the screen width Window win = this.getWindow(); win.getDecorView().setPadding(0, 0, 0, 0); WindowManager.LayoutParams lp = win.getAttributes(); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; lp.gravity = Gravity.TOP;//Set the dialog box to be displayed on top win.setAttributes(lp);
2. Set the style
<style name="dialogstyle"> <!--Set the background of the dialog--> <item name="android:windowBackground">@android:color/transparent</item> <!--Set Dialog's windowFrame box to none--> <item name="android:windowFrame">@null</item> <!--Set No Title--> <item name="android:windowNoTitle">true</item> <!--Whether it floats above the activity--> <item name="android:windowIsFloating">true</item> <!--Is it translucent--> <item name="android:windowIsTranslucent">true</item> <!--Set the window content not to cover--> <item name="android:windowContentOverlay">@null</item> <!--Set animation, use Animation.Dialog--> here to let it inherit the system <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <!--Whether the background is blurred display--> <item name="android:backgroundDimEnabled">true</item> </style>
3. Apply styles
<activity android:name="com.lpl.topnews.ShowDialogActivity" android:theme="@style/dialogstyle" ></activity>