Question

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

Was it helpful?

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>

OTHER TIPS

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

    getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

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;

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top