Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改ProgressDialog的背景_Android_Android Layout_Android Dialog - Fatal编程技术网

Android 更改ProgressDialog的背景

Android 更改ProgressDialog的背景,android,android-layout,android-dialog,Android,Android Layout,Android Dialog,我正在尝试更改ProgressDialog的背景。我在网上搜索并找到了各种建议(如),但我无法替换ProgressDialog的实际背景。相反,我在对话框后面得到了另一个背景(黄色): 我的风格: <style name="StyledDialog" parent="@android:style/Theme.Dialog"> <item name="android:windowBackground">@drawable/panel_background</

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

我的风格:

<style name="StyledDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowBackground">@drawable/panel_background</item>
</style>
drawable是SDK中包含的同一个9补丁,我刚刚更改为颜色。如果能给我一些提示,说明我做错了什么,我将不胜感激。

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

步骤1:定义继承自
主题的主题。对话框

ProgressDialog dialog = new ProgressDialog(this, R.style.StyledDialog);
dialog.setTitle("The title");
dialog.setMessage("The message.");
dialog.show();
<style name="MyTheme" parent="@android:style/Theme.Dialog">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:textColorPrimary">#000000</item>
</style>
这将问题中的黑色区域设置为黄色

步骤3:将
MyTheme
应用于
ProgressDialog
而不是
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>
ProgressDialog dialog = new ProgressDialog(this, R.style.MyTheme);
结果如下:

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

您可以试试我的。它基本上设置了一个颜色过滤器的绘图

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.widget.ProgressBar;

public class ColoredProgressBar extends ProgressBar {
   public ColoredProgressBar(Context context) {
      super(context);
      if (!isInEditMode())
         init();
   }

   public ColoredProgressBar(Context context, AttributeSet attrs) {
      super(context, attrs);
      if (!isInEditMode())
         init();
   }

   public ColoredProgressBar(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
      if (!isInEditMode())
         init();
   }

   /**
    * Changes color.
    */
   private void init() {
      getIndeterminateDrawable().setColorFilter(Color.BLUE, android.graphics.PorterDuff.Mode.MULTIPLY);
   }
}

我认为这里的问题是标题、消息和图像有自己的背景设置,而不是在对话框的背景上透明。你需要做的是迭代对话框视图的所有子项,并将它们的背景设置为透明。您好,回答得很好,但一些边框仍然是黑色的。你知道如何删除黑色边框了吗@Shoebahmedsidiques有人在API级别8上测试过这个吗?不适用于我:'(@lyc001您需要dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);或@android:color/transparent