7

I recently migrated my app to Material Design and I stumbled upon this problem with my Alert Dialogs:

dialog appears to be having two backgrounds and I don't know how to get rid of the outer background

I'm applying the dialog style like this:

<item name="android:alertDialogTheme">@style/Theme.AlertDialog</item>

and Theme.AlertDialog looks like this:

<style name="Theme.AlertDialog" parent="Base.V14.Theme.AppCompat.Dialog">
    <item name="colorPrimary">@color/theme_primary</item>
    <item name="colorPrimaryDark">@color/theme_primary_dark</item>
    <item name="colorAccent">@color/theme_accent_dark</item>
</style>

This is happening on my Kitkat device and it works fine on Lollipop. Can you help me with getting rid of that outer background?

Adrian
  • 717
  • 11
  • 18
  • You should use the new [android.support.v7.app.AlertDialog](http://stackoverflow.com/a/29810469/1233652). – Alex Lipov Jan 03 '16 at 16:00
  • Well, this is actually a preference screen and the dialog that you are seeing, is actually a list preference and I don't think that I can change the type of the dialog. The accepted answer works fine though... – Adrian Jan 04 '16 at 09:34

5 Answers5

10

The point is here:

<style name="Theme.AlertDialog" parent="Base.V14.Theme.AppCompat.Dialog">
    ...
    <item name="colorPrimary">@color/theme_primary</item>
    <item name="colorPrimaryDark">@color/theme_primary_dark</item>
    <item name="colorAccent">@color/theme_accent_dark</item>
    ...
    <item name="android:windowBackground">@android:color/transparent</item>
    ...
</style>
SilentKnight
  • 13,761
  • 19
  • 49
  • 78
  • a transparent background is an issue on edge devices as there is no default dialog background so the whole dialog is transparent – 2cupsOfTech Aug 11 '16 at 16:46
  • 2
    it's makes transparent background on all devices but need only remove weird border. How to do that? – Trancer Dec 11 '16 at 17:13
4

As ironman told me here, be sure that you import the right class.

Right : import android.support.v7.app.AlertDialog;

Wrong : import android.app.AlertDialog;

Community
  • 1
  • 1
adiel
  • 91
  • 3
0

Use the theme in parent

AlertDialog.THEME_DEVICE_DEFAULT_LIGHT
Akash
  • 681
  • 3
  • 17
0

Add below styles . You have to customise background also.

    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:background">@android:color/transparent</item>

Using below also works

<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:background">@android:color/transparent</item>

Also You can set in your code by using

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

and this should be before setContentView

dialog.setContentView(R.layout.dialog);
Tulsiram Rathod
  • 1,926
  • 2
  • 19
  • 29
  • Thank you, the only thing that I had to do was to add @android:color/transparent to my Theme.AlertDialog. As pointed out by SilentKnight in his answer. – Adrian Apr 02 '15 at 07:42
  • 1
    the solution doesn't seem to work for samsung edge devices – 2cupsOfTech Aug 11 '16 at 16:51
0

I had the exact same symptom but for me it was actually that I had used the standard frameworks AlertDialog (and its Builder) instead of android.support.v7.app.AlertDialog, switching to use the one from the support library fixed the issue for me.

Maks
  • 7,562
  • 6
  • 43
  • 65