Skip to content Skip to sidebar Skip to footer

How To Set Default Progress Dialog Spinner Color By Programatically In Android

I am trying to change default progress dialog spinner color..but I went some tutorial but not usefull progressDialog.setMessage('Loading...'); progressDialog.setIndetermina

Solution 1:

Try this but i doesn't had text like loading...

finalProgressDialogdialog= ProgressDialog.show(MainActivity.this, null, null);
        ProgressBarspinner=newandroid.widget.ProgressBar(MainActivity.this, null,android.R.attr.progressBarStyle);
        spinner.getIndeterminateDrawable().setColorFilter(Color.parseColor("#53CBF1"), android.graphics.PorterDuff.Mode.SRC_IN);
        dialog.getWindow().setBackgroundDrawable(newColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.setContentView(spinner);
        dialog.setCancelable(false);
        dialog.show();

Solution 2:

change colorAccent in Your main theme`

<stylename="AppTheme"parent="Theme.AppCompat.Light.DarkActionBar"><itemname="colorPrimary">@color/colorPrimary</item><itemname="colorPrimaryDark">@color/colorPrimaryDark</item><itemname="colorAccent">@color/yourcolor</item></style>

For all devices support below 21 you using code by custom layout to progress dialog...

custom_progressdialog.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@android:color/transparent"android:id="@+id/rl"android:padding="5dp"

><ProgressBarandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@android:color/transparent"android:id="@+id/progressbar"android:layout_centerVertical="true"

        /><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="Loading..."android:layout_toRightOf="@+id/progressbar"android:layout_centerVertical="true"
        /></RelativeLayout>

Code

    progressDialog=newProgressDialog(demo.this);
    progressDialog.show();
    progressDialog.setContentView(R.layout.custom_progressdialog);
    ProgressBar progressbar=(ProgressBar)progressDialog.findViewById(R.id.progressbar);
    progressbar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#C60000"), android.graphics.PorterDuff.Mode.SRC_IN);
    progressDialog.setCancelable(true);

Solution 3:

Step 1:

In res Directory, Create 1 XML File and name it progress.xml, This is the code for the file:

<?xml version="1.0" encoding="utf-8"?><rotatexmlns:android="http://schemas.android.com/apk/res/android"android:pivotX="50%"android:pivotY="50%"android:fromDegrees="0"android:toDegrees="360"><shapeandroid:shape="ring"android:innerRadiusRatio="3"android:thicknessRatio="8"android:useLevel="false"><sizeandroid:width="76dip"android:height="76dip" /><gradientandroid:type="sweep"android:useLevel="false"android:startColor="#447a29"android:endColor="#447a29"android:angle="0"
             /></shape></rotate>

Step 2:

Modify android:startColor and android:endColor as whatever Color you want.

Step 3:

set that progress.xml in ProgressBar's backgound .

<ProgressBar
  android:id="@+id/ProgressBar01" 
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:background ="@xml/progress">

Answer based on This Page, By Chirag Raval.

Post a Comment for "How To Set Default Progress Dialog Spinner Color By Programatically In Android"