Dialog skinning with AppCompat-v7 22 results in ugly shadows on api < 21

I’m using AppCompat to write a material design styled app. Since AppCompat does not affect dialogs, I’m skinning the dialogs as such:


  • How to make list elements get DragEvents after scrolling
  • Okhttp refresh expired token when multiple requests are sent to the server
  • Any easy, generic way in Android to get the root View of a layout?
  • How to change the Font styles and face in Android?
  • How to determine the current IME in Android?
  • Weird exception: Cannot cast String to Boolean when using getBoolean
  • <style name="AppTheme.Base" parent="Theme.AppCompat">
        <!-- Set AppCompat’s color theming attrs -->
        <item name="colorPrimary">@color/green</item>
        <item name="colorPrimaryDark">@color/green_darker</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:alertDialogTheme">@style/alertDialog</item>
        <item name="android:dialogTheme">@style/alertDialog</item>
    <style name="alertDialog" parent="Theme.AppCompat.Dialog">
        <item name="colorPrimary">@color/green</item>
        <item name="colorPrimaryDark">@color/green_darker</item>
        <item name="colorAccent">@color/accent</item>

    I am gettings exactly what I wanted on android api >= 21, but on other devices I end up with a “box” around the dialogs.

    Is there a way to get rid of the “box” around the dialog and even get the colors and material theme applied on api < 21, preferably without any additional depencendies?

    App on Api < 21:

    App on API < 21

    App on API >= 21:

    App on API >= 21

    Related posts:

    AutocompleteTextView suggestion list goes up
    Android TimePicker AM/PM button not invoking onTimeChanged
    Changing z-index (z-order) of map marker for Maps V2 in Android
    android: difference between ACTION_UP and ACTION_POINTER_UP
    Check if ScrollView is higher than screen / scrollable
    Trying to implement camera permissions for android M getting No virtual method checkSelfPermission
  • Maintain WebView content scroll position on orientation change
  • Accessing the Android media stream for audio visualization
  • Can I tweak my android emulator to make it fast?
  • How to fix NPE in ViewRoot#updateBidiOptions?
  • Token that identify the user
  • How to Send BroadCast from one app to another app
  • 5 Solutions collect form web for “Dialog skinning with AppCompat-v7 22 results in ugly shadows on api < 21”

    With the new AppCompat v22.1 you can use the new android.support.v7.app.AlertDialog or the new AppCompatDialog

    Just use a code like this (of course in your case you have to use a custom layout to have the progress bar)

    import android.support.v7.app.AlertDialog
    AlertDialog.Builder builder =
           new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
                builder.setMessage("Lorem ipsum dolor ....");
                builder.setPositiveButton("OK", null);
                builder.setNegativeButton("Cancel", null);

    And use a style like this:

    <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
            <item name="colorAccent">#FFCC00</item>
            <item name="android:textColorPrimary">#FFFFFF</item>
            <item name="android:background">#5fa3d0</item>

    In case anyone is still looking for a simple and effective solution, just add this line to your “alertDialog” style:

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

    P.S. changing this property also affects PreferenceFragment’s dialogs on API >= 21, so make sure you are using different styles: with transparent bg for API < 21, and without any changes for API >= 21

    I had the exact same problem with the new AppCompat 22 library when using android.support.v7.app.AlertDialog for all my AlertDialogs, but the extra background layers only affected ProgressDialogs.

    All my AlertDialogs when styled using my custom theme looked great, but the ProgressDialog’s had the weird overlay on the background as described in the OP.

    An option I had was to set a specific style each time I constructed a ProgressBar, but I was looking for an application wide solution.

    With the help of these two links:

    How to Style AlertDialogs like a Pro and Joerg Richter Blog I was able to get rid of the extra layer drawn on < 21 ProgressDialogs.

    The issue I found was that on all versions the ProgressBar draws its background based on what is defined by default in “android:alertDialogStyle”.

    So to get rid of the extra layer, I had to define my own styles and set them for “android:alertDialogStyle”. In doing so, I’m also overriding the default layouts applied to ProgressDialogs.

    Here’s my themes.xml:

    <item name="android:alertDialogTheme">@style/MyAlertDialogTheme</item>
    <item name="alertDialogTheme">@style/MyAlertDialogTheme</item>
    <item name="android:alertDialogStyle">@style/MyAlertDialogStyles</item>

    And my styles.xml:

    <style name="MyAlertDialogTheme">
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
        <item name="android:background">@color/theme_alert_dialog_background</item>
        <item name="colorAccent">@color/theme_accent_1</item>
    <style name="AlertDialog">
        <item name="android:fullDark">@android:color/transparent</item>
        <item name="android:topDark">@android:color/transparent</item>
        <item name="android:centerDark">@android:color/transparent</item>
        <item name="android:bottomDark">@android:color/transparent</item>
        <item name="android:fullBright">@android:color/transparent</item>
        <item name="android:topBright">@android:color/transparent</item>
        <item name="android:centerBright">@android:color/transparent</item>
        <item name="android:bottomBright">@android:color/transparent</item>
        <item name="android:bottomMedium">@android:color/transparent</item>
        <item name="android:centerMedium">@android:color/transparent</item>

    ProgressDialog – Try for below android 5




    You may download revision 22.1.0 (updated a few days ago) and use android.support.v7.app.AlertDialog

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.