28

I have an activity which is with the theme Theme.Transparent which is:

<style name="Theme.Transparent" parent="android:Theme.Dialog">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:gravity">top</item>
</style>

i'm trying to get rid of the border and the padding around it.. i want to make fill the horizontal of the screen. and no gray border. please help :) enter image description here

Guy
  • 5,370
  • 6
  • 25
  • 30

4 Answers4

98

Be sure to create your Dialog referencing your custom theme:

Dialog dialog = new Dialog(this, R.style.MyDialogTheme);

Your custom theme needs to fill the screen and disable a couple of Android framework defaults:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyDialogTheme" parent="android:Theme.Dialog">
        <!-- Fill the screen -->
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>

        <!-- No backgrounds, titles or window float -->
        <item name="android:windowBackground">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">false</item>      

        <!-- Just to prove it's working -->
        <item name="android:background">#ff0000</item>
    </style>

</resources>
David Snabel-Caunt
  • 57,804
  • 13
  • 114
  • 132
  • 4
    THANKS! :) @null did the trick! i can only award the bounty in 17 hours. but i will. thanks a lot. – Guy Jan 16 '12 at 14:35
  • Happy to help; surprised no-one else had answered this one. It's certainly not obvious, but checking the Android source on github can help figure out what's happening by default! – David Snabel-Caunt Jan 16 '12 at 16:13
  • I wish I could upvote this twice. Note to peeps: nulling out the windowBackground is the only way to get the dialog to display FLUSH - i.e. with no hint of the view behind it. David, you rock. – HappyKatz Dec 10 '15 at 15:08
  • Thank you @DavidCaunt sir for amazing solution +1 – Harin Kaklotar Jul 19 '17 at 12:15
17

Same as above but doing it in code rather than in xml worked for me.

    getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
user3633840
  • 171
  • 1
  • 2
  • I found out that this way doesn’t work as good as the accepted answer. This way just fade any padding around the dialog but doesn’t really remove padding. This is a problem when the user click around the dialog to cancel it but it won’t be cancelled because the padding still there but transparented. – Mansour Fahad Aug 10 '14 at 12:33
  • just perfect buddy !! saved me! – mamzi May 23 '18 at 19:10
7

Set width and height to match parent container.

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    WindowManager.LayoutParams wmlp = dialog.getWindow()
            .getAttributes();
    wmlp.width = android.view.WindowManager.LayoutParams.MATCH_PARENT;
    wmlp.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
rajeswari ratala
  • 650
  • 7
  • 14
-1

The following works perfectly for me. It lets me have a full-width dialog (fills the screen's width with no padding) but with wrap_content for height, and it retains all my other stylings that I do in my builder:

<item name="windowMinWidthMajor">100%</item>
<item name="windowMinWidthMinor">100%</item>

<item name="android:windowBackground">@null</item>
<item name="android:windowIsFloating">true</item>

<item name="android:background">#ffffff</item>

Background is required or else it does a weird repeat thing, but just set this to the color you want your dialog background to be. WindowBackground and WindowIsFloating are required to make the size wrap correctly.

Add your theme to your builder like so:

builder = new AlertDialog.Builder(_context, R.style.DialogTheme); and you're good to go!

Elliptica
  • 3,928
  • 3
  • 37
  • 68