Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default ProgressDialog circle color in android

I am using ProgressDialog for showing progressbar

            ProgressDialog progressDialog = new ProgressDialog(context);
            progressDialog.setCancelable(false);
            progressDialog.setMessage(message);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progressDialog.show();

And it is coming like this

enter image description here

I want to change the green color of the circle to red. is there any way?

I tried

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

But not working.

like image 267
dev Avatar asked Dec 01 '15 10:12

dev


4 Answers

In style.xml create style for dialog box :

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

In this "android:textColorPrimary" need to define color you want to show and in java code define style of ProgressDialog like :

ProgressDialog progressDialog = new ProgressDialog(context,R.style.AppCompatAlertDialogStyle);

MORE : http://androidprogressdialogcustomcolor.blogspot.in/

like image 96
Kapil Rajput Avatar answered Oct 16 '22 05:10

Kapil Rajput


Add Style.xml

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

set style to progress dialog

pdialog = new ProgressDialog(context, R.style.MyAlertDialogStyle);
like image 43
Ramesh Prajapati Avatar answered Oct 16 '22 07:10

Ramesh Prajapati


enter image description here

Create layout for progress dialog as named as custom_progress_dialog.xml in drawable folder.

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

make sure that indeterminate = true and android:indeterminateDrawable="@drawable/custom_progress_background" In the activity layout where you want to use the loader

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/loadingPanel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <ProgressBar
        android:layout_width="wrap_content"
        style="?android:attr/progressBarStyleLarge"
        android:layout_height="wrap_content"
        android:indeterminateDrawable="@drawable/custom_progress_dialog"
        android:indeterminate="true" />
</RelativeLayout>
like image 14
Umesh Sonawane Avatar answered Oct 16 '22 05:10

Umesh Sonawane


This is not a perfect solution, but may help.

Also check my previous comment. https://stackoverflow.com/a/39687893/2598453

final ProgressDialog progress = new ProgressDialog(this);
progress.setMessage(getString(R.string.progress_message));
progress.setIndeterminate(true);
progress.setCancelable(false);

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    Drawable drawable = new ProgressBar(this).getIndeterminateDrawable().mutate();
    drawable.setColorFilter(ContextCompat.getColor(this, R.color.colorAccent),
            PorterDuff.Mode.SRC_IN);
    progress.setIndeterminateDrawable(drawable);
}

progress.show();
like image 9
Milan Hlinák Avatar answered Oct 16 '22 06:10

Milan Hlinák