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...
final ProgressDialog dialog = ProgressDialog.show(MainActivity.this, null, null);
ProgressBar spinner = new android.widget.ProgressBar(MainActivity.this, null,android.R.attr.progressBarStyle);
spinner.getIndeterminateDrawable().setColorFilter(Color.parseColor("#53CBF1"), android.graphics.PorterDuff.Mode.SRC_IN);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(spinner);
dialog.setCancelable(false);
dialog.show();
Solution 2:
change colorAccent in Your main theme`
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="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"?>
<RelativeLayout
xmlns: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"
>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:id="@+id/progressbar"
android:layout_centerVertical="true"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Loading..."
android:layout_toRightOf="@+id/progressbar"
android:layout_centerVertical="true"
/>
</RelativeLayout>
Code
progressDialog=new ProgressDialog(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"?>
<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="76dip" android:height="76dip" />
<gradient android: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"