9

Can you help my figure out why is my alert dialog BLACK?!

Recently i changed my app theme to support material design, but my alert dialog got black!

Here is my create dialog Code:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(TestActivity.this);
    alertDialog.setCancelable(true);
    alertDialog.setTitle("sample");
    alertDialog.setItems(new String[] { "a", "b" }, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

        }
    });

    alertDialog.show();

and its my main style and dialog style

<style name="MaterialTheme" parent="Theme.AppCompat.NoActionBar">

    <item name="android:alertDialogStyle">@style/AppDialog</item>
    <item name="android:alertDialogTheme">@style/AppDialog</item>
    <item name="android:textColor">@color/black</item>
    <item name="android:textColorPrimary">@color/black</item>
    <item name="android:dialogTheme">@style/AppDialog</item>
    <item name="colorPrimaryDark">@color/myPrimaryDarkColor</item>
    <item name="android:textColorHint">@color/gray_1</item>
    <item name="colorAccent">@color/myAccentColor</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="android:windowBackground">@color/black</item>
</style>

<style name="AppDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">#FFC107</item>
    <item name="android:textColorPrimary">#FFFFFF</item>
    <item name="android:background">#4CAF50</item>
</style>
Samira
  • 844
  • 13
  • 17
  • see the excepted ans, might be you can resolve your issue with this approach > https://stackoverflow.com/questions/3118601/how-can-i-change-the-background-of-android-alert-dialogs – Maniya Joe Sep 07 '15 at 07:29

2 Answers2

4

You don't set theme for AlertDialog, for using theme, change code to:

ContextThemeWrapper ctw = new ContextThemeWrapper(TestActivity.this, R.style.AppDialog);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ctw);
AliSh
  • 10,085
  • 5
  • 44
  • 76
2

you must use a light theme with your alertdialog builder such as the THEME_HOLO_LIGHT.

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this,AlertDialog.THEME_HOLO_LIGHT);
Boody
  • 144
  • 7