如何更改进度对话框的背景颜色?
问题描述:
我正在与纺纱厂合作,并希望将窗口的背景颜色从黑色变为白色。 下面是进度对话框代码:如何更改进度对话框的背景颜色?
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>
在那里,你可以定义整个窗口的背景颜色(问题中的黄色),字体颜色等。真正重要的是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对话框=新ProgressDialog(此,R.style.MyTheme);
谢谢,这帮助我解决了我的问题! – GAD
不客气,你能接受答案吗? –