GAD
GAD

Reputation: 27

How to change progress dialog's background color?

I'm working with spinners and want to change background color of window from black to white. Here is the codes for progress dialog:

        if (countProgress > 0) {
        countProgress += 1;
        return;
    }
    final ProgressDialog progressDialog = new ProgressDialog(activity, DialogFragment.STYLE_NO_TITLE);
    progressDialog.setIndeterminateDrawable(activity.getResources().getDrawable(R.drawable.progress));
    progressDialog.setMessage(msg);
    progressDialog.setCancelable(false);
    progressDialog.setCanceledOnTouchOutside(false);
    stackProgressDialog.push(progressDialog);
    countProgress = 1;
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            progressDialog.show();

        }
    });

and here is the drawable xml :

<?xml version="1.0" encoding="utf-8"?>
rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/logo_only_64dp"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="360"
android:repeatCount="infinite"/>

Upvotes: 1

Views: 1791

Answers (1)

Luiz Fernando Salvaterra
Luiz Fernando Salvaterra

Reputation: 4182

Step 1: Define a theme that inherits from Theme.Dialog:

<style name="MyTheme" parent="@android:style/Theme.Dialog">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:textColorPrimary">#000000</item>
</style>

There, you can define things like the background color for the whole window (yellow in the question), font colors etc. What's really important is the definition of android:alertDialogStyle. This style controls the appearance of the black area in the question.

Step 2: Define the CustomAlertDialogStyle:

<style name="CustomAlertDialogStyle">
    <item name="android:bottomBright">@color/yellow</item>
    <item name="android:bottomDark">@color/yellow</item>
    <item name="android:bottomMedium">@color/yellow</item>
    <item name="android:centerBright">@color/yellow</item>
    <item name="android:centerDark">@color/yellow</item>
    <item name="android:centerMedium">@color/yellow</item>
    <item name="android:fullBright">@color/yellow</item>
    <item name="android:fullDark">@color/yellow</item>
    <item name="android:topBright">@color/yellow</item>
    <item name="android:topDark">@color/yellow</item>
</style>

This sets the black area in the question to yellow.

Step 3: Apply MyTheme to the ProgressDialog, not CustomAlertDialogStyle:

ProgressDialog dialog = new ProgressDialog(this, R.style.MyTheme);

Upvotes: 1

Related Questions