在问题下方的Aleks G评论指明了正确的方向。对话框的外观由单独的样式(android:alertDialogStyle
)定义。但是,不能将样式直接应用于ProgressDialog
。现在,如何获得那个黄色背景?
步骤1:定义一个从Theme.Dialog
继承的主题:
<style name="MyTheme" parent="@android:style/Theme.Dialog">
<item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
<item name="android:textColorPrimary">
</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>
这将把问题区域中的黑色设置为黄色。
第三步:将MyTheme
应用于ProgressDialog,而不是CustomAlertDialogStyle
:
ProgressDialog dialog = new ProgressDialog(this, R.style.MyTheme);
下面是结果:
![Styled ProgressDialog](https://istack.dev59.com/jCORH.webp)
同样的步骤也适用于AlertDialog
(它是ProgressDialog
的父类)。