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

查看:166
本文介绍了更改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>

在code表示启动 ProgressDialog

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

的绘制是包含在SDK相同的9补丁,我只是改变了颜色。我将非常AP preciate一些提示什么,我做错了。

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.

推荐答案

的阿莱克斯克注释​​(以下问题)在正确的方向点。对话框的外观是由一个单独的样式定义(安卓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?

第1步:定义一个主题,它继承自 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>

在这里,你可以定义的东西,如背景色的全部的窗口(黄中的问题),字体颜色等。机器人的定义什么是真正重要的是: 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

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

而这里的结果是:

And here's the result:

同样的方法适用于 AlertDialog (这是父类的 ProgressDialog )。

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

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

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