3

I am having a theme in the following way:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primaryDark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="alertDialogTheme">@style/AppTheme.Dialog</item>
</style>

<style name="AppTheme.Dialog" parent="Theme.AppCompat.Dialog.Alert">
    <item name="colorAccent">@color/accent</item>
</style>

However, when I create AlertDialogs inside my app, they are not themed at all. Other components like the ActionBar are being colored properly. Am I missing something?

I am using the AppCompat version com.android.support:appcompat-v7:23.1.1 and my device has Android 4.4.4 installed.

flxapps
  • 1,066
  • 1
  • 11
  • 24
  • http://stackoverflow.com/questions/26455919/material-design-not-styling-alert-dialogs/29810469#29810469 – Gabriele Mariotti Feb 28 '16 at 12:58
  • 7
    Thanks, my problem was doing `android:alertDialogTheme` vs just `alertDialogTheme`.... after 4 years of android development I still don't understand why this makes a difference... – em_ Aug 09 '17 at 15:08

2 Answers2

12

For anyone stumbling upon this question with similar problems: Please double-check that you are using the AlertDialog.Builder from the support library package, so the import statement should look like:

import android.support.v7.app.AlertDialog;

In my case I was importing android.app.AlertDialog which led to the wrong results.

flxapps
  • 1,066
  • 1
  • 11
  • 24
0

When creating the AlertDialog you can set a theme to use:

import android.support.v7.app.AlertDialog;
Stanojkovic
  • 1,612
  • 1
  • 17
  • 24
  • As I said in the opening post, I am using the attribute alertDialogTheme which should have the same effect. – flxapps Feb 28 '16 at 22:09