Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change style of ProgressDialog

Is it possible to change ProgressBar style of progress dialog. If yes, then how can I do it?

like image 710
Aram Avatar asked Jan 31 '12 09:01

Aram


People also ask

What is ProgressDialog in Android?

ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar , which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress.

How can change horizontal progress bar color in android programmatically?

Then use the below code to change the progressbar colorloadingProgressBar. getProgressDrawable(). setColorFilter( Color. parseColor("#2a4c6b"), android.


1 Answers

You can style your progress dialog this way: create a drawable file with your ring shape (circular_progress_dialog.xml)

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">
<shape
    android:innerRadiusRatio="2.5"
    android:shape="ring"
    android:thickness="2dp"
    android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 -->

    <gradient
        android:angle="0"
        android:endColor="@color/main_background"
        android:startColor="@color/main_orange"
        android:type="sweep"
        android:useLevel="false" />
</shape>
</rotate>

one to style your progress bar

 <style name="ProgressBar" parent="@android:style/Widget.ProgressBar">
    <item name="android:layout_centerHorizontal">true</item>
    <item name="android:layout_centerVertical">true</item>
    <item name="android:visibility">gone</item>
    <item name="android:background">@color/transparency_pleca</item>
    <item name="android:indeterminateDrawable">@drawable/circular_progress_dialog</item>
</style>

Notice your "android:indeterminateDrawable" property

Yout can create an instance of ProgressDialog and add your style with

// create progressDialog
final ProgressDialog myProgressDialog = new  ProgressDialog(MyActivity.this);
myProgressDialog.setProgressStyle(R.style.ProgressBar)
myProgressDialog.show();
like image 68
AlbertoRuvel Avatar answered Nov 15 '22 17:11

AlbertoRuvel