如何更改进度对话框的背景颜色?

How to change progress dialog's background color?

我正在使用微调器并想将 window 的背景颜色从黑色更改为白色。 这是进度对话框的代码:

        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();

        }
    });

这是可绘制对象 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"/>

第 1 步:定义继承自 Theme.Dialog 的主题:

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

在那里,您可以定义诸如整个 window(问题中的黄色)、字体颜色等的背景颜色。真正重要的是 android:alertDialogStyle 的定义。此样式控制问题中黑色区域的外观。

第 2 步:定义 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>

这会将问题中的黑色区域设置为黄色。

第 3 步:将 MyTheme 应用到 ProgressDialog,而不是 CustomAlertDialogStyle:

ProgressDialog 对话框 = new ProgressDialog(this, R.style.MyTheme);