如何在android中更改默认ProgressDialog圆形颜色

如何在android中更改默认ProgressDialog圆形颜色,android,android-progressbar,Android,Android Progressbar,我正在使用ProgressDialog显示progressbar ProgressDialog progressDialog = new ProgressDialog(context); progressDialog.setCancelable(false); progressDialog.setMessage(message); progressDialog.setProgressStyle(Pro

我正在使用
ProgressDialog
显示progressbar

            ProgressDialog progressDialog = new ProgressDialog(context);
            progressDialog.setCancelable(false);
            progressDialog.setMessage(message);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progressDialog.show();
事情是这样的

我想把圆圈的绿色改成红色。有办法吗

我试过了

.getIndeterminateDrawable().setColorFilter(0xFFFFFFFF, android.graphics.PorterDuff.Mode.MULTIPLY);
但不起作用

试试这个:

将颜色设置为红色的示例:

ProgressBar spinner = new android.widget.ProgressBar(
                context,
                null,
                android.R.attr.progressBarStyle);

spinner.getIndeterminateDrawable().setColorFilter(0xFFFF0000, android.graphics.PorterDuff.Mode.MULTIPLY);

在应用程序主题中,更改颜色重音

<style name="AppTheme.Bash" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">Add your color here</item>
    <item name="android:windowBackground">@color/gray</item>
</style>

@颜色/原色
@颜色/原色暗
在这里添加您的颜色
@颜色/灰色

在style.xml创建样式对话框中使用所需的任何颜色

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/black</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:background">@color/grey_dialog_box</item>
</style>
更多信息:

在drawable文件夹中创建名为custom_progress_dialog.xml的进度对话框布局

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
    android:toDegrees="360">
    <shape android:shape="ring" android:innerRadiusRatio="3"
        android:thicknessRatio="8" android:useLevel="false">

        <size android:width="56dip" android:height="56dip" />

        <gradient android:type="sweep" android:useLevel="false"
            android:startColor="@android:color/transparent"
            android:endColor="#1e9dff"
            android:angle="0"
             />

    </shape>
</rotate>

这不是一个完美的解决方案,但可能会有所帮助

也请检查我之前的评论。

final ProgressDialog progress=新建ProgressDialog(此);
progress.setMessage(getString(R.string.progress_message));
progress.setUndeterminate(true);
进度。可设置可取消(false);
if(Build.VERSION.SDK\u INT
定制颜色进度条的完美而简单的解决方案。

并在布局中使用它

<RelativeLayout
        android:id="@+id/loadingPanel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:visibility="gone">

        <com.mayproject.views.CustomProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </RelativeLayout>

如果您想定义特殊颜色,而不需要继承或专用XML,您可以使用以下内容:

/** Styles a ProgressDialog to use a themed Spinner. */
public void setStyledProgressDialog(final Context pContext, final ProgressDialog pProgressDialog, final int pColorResourceId) {
    // Allocate a new ProgressBar.
    final ProgressBar lProgressBar = new android.widget.ProgressBar(pContext, null, android.R.attr.progressBarStyle);
    // Configure the IndeterminateDrawable.
    lProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(pContext, pColorResourceId), android.graphics.PorterDuff.Mode.MULTIPLY);
    // Assign the ProgressBar to the ProgressDialog.
    pProgressDialog.setIndeterminateDrawable(lProgressBar.getIndeterminateDrawable());
}

如果已使用材质对话框库(),最简单的解决方案可能是使用该库中的进度对话框。圆圈将自动使用原色着色:

MaterialDialog dialog = new MaterialDialog.Builder(context)
                    .content(R.string.loading)
                    .progress(true, 0)
                    .show();
添加Style.xml

<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/colorPrimary</item>
</style>

从ProgressDialog使用的android资源中获取资源

final ProgressDialog progress = new ProgressDialog(context);
progress.setTitle("Loading");
progress.setMessage("Wait while loading...");
progress.setCancelable(false); // disable dismiss by tapping outside of the dialog
progress.show();
ProgressBar progressbar=(ProgressBar)progress.findViewById(android.R.id.progress);
progressbar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#C60000"), android.graphics.PorterDuff.Mode.SRC_IN);

可能重复的问题可能是重复的问题。请检查>@MohanRex您提出的可能的副本是错误的。因为这些都是关于android.widget.ProgressBar的问题,而这个问题是关于android.app.ProgressDialog的。两者完全不同。因此,删除错误的标记这不会更改圆形颜色。此外,“显示”是静态的,不能与ProgressDialog的新实例一起使用。@color/black这是更改加载程序微调器/圆形颜色的关键值。在Kotlin上仍然有效。正如前面所说,关键是新风格的“颜色口音”。最好的答案!只有一个完全按照asker的要求做。
/** Styles a ProgressDialog to use a themed Spinner. */
public void setStyledProgressDialog(final Context pContext, final ProgressDialog pProgressDialog, final int pColorResourceId) {
    // Allocate a new ProgressBar.
    final ProgressBar lProgressBar = new android.widget.ProgressBar(pContext, null, android.R.attr.progressBarStyle);
    // Configure the IndeterminateDrawable.
    lProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(pContext, pColorResourceId), android.graphics.PorterDuff.Mode.MULTIPLY);
    // Assign the ProgressBar to the ProgressDialog.
    pProgressDialog.setIndeterminateDrawable(lProgressBar.getIndeterminateDrawable());
}
MaterialDialog dialog = new MaterialDialog.Builder(context)
                    .content(R.string.loading)
                    .progress(true, 0)
                    .show();
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/colorPrimary</item>
</style>
pdialog = new ProgressDialog(context, R.style.MyAlertDialogStyle);
final ProgressDialog progress = new ProgressDialog(context);
progress.setTitle("Loading");
progress.setMessage("Wait while loading...");
progress.setCancelable(false); // disable dismiss by tapping outside of the dialog
progress.show();
ProgressBar progressbar=(ProgressBar)progress.findViewById(android.R.id.progress);
progressbar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#C60000"), android.graphics.PorterDuff.Mode.SRC_IN);