Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is My Android Alert dialog BLACK?

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>
like image 242
Samira Avatar asked Sep 06 '15 10:09

Samira


People also ask

What is the difference between an alert and an alert dialog?

AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .

What is Android alert?

Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.


2 Answers

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);
like image 163
AliSh Avatar answered Oct 16 '22 18:10

AliSh


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);
like image 2
Boody Avatar answered Oct 16 '22 20:10

Boody