更改 ProgressDialog 的背景 [英] Change background of ProgressDialog

查看:27
本文介绍了更改 ProgressDialog 的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改 ProgressDialog 的背景.我在网上搜索并找到了各种建议(例如 如何从对话框中删除边框?),但我无法替换 ProgressDialog 的实际背景.相反,我在对话框后面得到了另一个背景(黄色):

I am trying to change the background of a ProgressDialog. I searched the net and found various suggestions (like How to remove border from Dialog?), but I am unable to replace the actual background of the ProgressDialog. Instead I get another background (yellow) behind the dialog:

我的风格:

<style name="StyledDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowBackground">@drawable/panel_background</item>
</style>

启动ProgressDialog的代码:

ProgressDialog dialog = new ProgressDialog(this, R.style.StyledDialog);
dialog.setTitle("The title");
dialog.setMessage("The message.");
dialog.show();

drawable 与 SDK 中包含的 9 个补丁相同,我只是更改了颜色.我将不胜感激一些提示我做错了什么.

The drawable is the same 9 patch that is included in the SDK, I just changed to color. I would greatly appreciate some hints what I am doing wrong.

推荐答案

Aleks G(问题下方)的评论指出了正确的方向.对话框的外观由单独的样式 (android:alertDialogStyle) 定义.但是不能将样式直接应用于 ProgressDialog.现在,我如何获得黄色背景?

The comment of Aleks G (below the question) points in the right direction. The appearance of the dialog is defined by a separate style (android:alertDialogStyle). But one cannot apply the style directly to a ProgressDialog. Now, how do I get that yellow background?

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

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>

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

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.

第 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>

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

This sets the black area in the question to yellow.

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

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

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

结果如下:

同样的过程适用于 AlertDialog(它是 ProgressDialog 的父类).

The same procedure works with AlertDialog (which is the parent class of ProgressDialog).

这篇关于更改 ProgressDialog 的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆