Material Design progressdialog
Asked Answered
C

3

16
 alertDialog = new ProgressDialog(this);                          
 alertDialog.setMessage(getResources().getString(R.string.loader));
 alertDialog.setCancelable(false);
 alertDialog.show();

Simply when I do this, green circle shows up with the word loading besides it. However when i DONT USE progress dialog, and i use a progressbar on the page I get a pink color as i have defined the below in my styles.xml

<item name="colorPrimary">@color/pink</item>
<item name="colorPrimaryDark">@color/pink</item>
<item name="colorAccent">@color/pink</item>

What is the solution of getting the circle pink color as in the progress bar on page?

Concordant answered 15/2, 2015 at 13:55 Comment(0)
E
11

For API 21+ you can define the following style to colour the material progress dialog. Note that this should be under values-v21 if you support lower platforms.

<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:alertDialogTheme">@style/MyAlertDialog</item>
</style>

<style name="MyAlertDialog" parent="android:Theme.Material.Light.Dialog.Alert">
    <item name="android:colorAccent">@color/pink</item>
</style>

<item name="colorAccent"> is for AppCompat whereas <item name="android:colorAccent"> is for API 21+. Material progress dialogs don't work with AppCompat, even with the new v22.1 Support lib AppCompatDialog.

You can see Chris Banes' answer here stating that he will not backport Progress Dialogs because they are "a bad pattern".

Elzaelzevir answered 30/4, 2015 at 13:27 Comment(3)
Fair comment that progress Dialog is a " bad pattern". Whats the suggested alternative?Wylie
@Wylie according to the developer guide: "However, if you need to indicate loading or indeterminate progress, you should instead follow the design guidelines for Progress & Activity and use a ProgressBar in your layout." instead of a ProgressDialog. So basically embed a ProgressBar somewhere and hide/unhide it as needed. I agree ProgressDialog tends to be a bad pattern (esp if non-cancelable), but I wish they would be more upfront and clear about it everywhere. Maybe even mention it in the ProgressDialog docs.Bourg
The link to a comment on Chris Banes' post now appears to be dead.Beal
B
2

This question is a bit old, but if you are using AppCompat, just add this attribute:

<item name="android:tint">@color/my_color_accent</item>

In your style

<style name="MaterialDialog" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:tint">@color/my_color_accent</item>
</style>

Hope this helps!

Bjork answered 3/5, 2016 at 10:9 Comment(0)
H
0

For me, these (and only these) style attributes were working:

<item name="android:indeterminateTint">@color/colorAccent</item>
<item name="android:progressTint">@color/colorAccent</item>
Hilariohilarious answered 1/7, 2021 at 17:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.