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

时间:2017-04-04 13:53:29

标签: android background spinner progressdialog

我正在使用微调器,并希望将窗口的背景颜色从黑色更改为白色。 以下是进度对话框的代码:

        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 个答案:

答案 0 :(得分:1)

步骤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>

在那里,您可以定义整个窗口的背景颜色(问题中的黄色),字体颜色等等。事实上,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);