timoschloesser timoschloesser - 3 years ago 148
Android Question

How to remove border from Dialog?

I have an activity which is shown in a dialog:

In order to remove border and rounded corners, i tried this:

<style name="ActivityDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@null</item>
<item name="android:windowFrame">@null</item>

The border is gone, but sadly also the margin around the dialog.

Answer Source

The border, round corners and margin are all defined by android:windowBackground. (Parameter android:windowFrame is already set to @null in Theme.Dialog style, therefore setting it to @null again has no effect.)

In order to remove the border and round corners you have to change the android:windowBackground appropriately. The Theme.Dialog style sets it to @android:drawable/panel_background. Which is a 9-patch drawable that looks like this (this one is the hdpi version):

enter image description here

As you can see the 9-patch png defines the margin, border and round corners of the dialog theme. To remove the border and round corners you have to create an appropriate drawable. If you want to keep the shadow gradient you have to create set of new 9-patch drawables (one drawable for each dpi). If you don't need the shadow gradient you can create a shape drawable.

The required style is then:

<style name="ActivityDialog" parent="@android:style/Theme.Dialog">      
   <item name="android:windowBackground">@drawable/my_custom_dialog_background</item>            
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download