Search code examples
user-interfaceandroid-activityandroid

remove border, padding from Dialog


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


Solution

  • 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>