27

I need to create a progressDialog only with the spinner and without the box (or at least with a smaller box and the image in the middle).

I don't want to add a spinner to my .xml (layout file) to load the spinner.

Is there any way to accomplish this? Thanks!

enter image description here

1

2 Answers 2

95

try this way:

pd = new ProgressDialog(Login.this,R.style.MyTheme);
pd.setCancelable(false);
pd.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
pd.show();

And create Theme in values\styles.xml

 <style name="MyTheme" parent="android:Theme.Holo.Dialog">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:windowBackground">@color/transparent</item>
    <item name="android:textColorPrimary">#FFFFFF</item>
     <item name="android:backgroundDimEnabled">false</item>
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:textStyle">normal</item>
    <item name="android:textSize">12sp</item>
</style>

And also add this Theme in values\styles.xml

 <style name="CustomAlertDialogStyle">
    <item name="android:bottomBright">@color/transparent</item>
    <item name="android:bottomDark">@color/transparent</item>
    <item name="android:bottomMedium">@color/transparent</item>
    <item name="android:centerBright">@color/transparent</item>
    <item name="android:centerDark">@color/transparent</item>
    <item name="android:centerMedium">@color/transparent</item>
    <item name="android:fullBright">@color/transparent</item>
    <item name="android:fullDark">@color/transparent</item>
    <item name="android:topBright">@color/transparent</item>
    <item name="android:topDark">@color/transparent</item>
</style>

And add values\colors.xml

<color name="transparent">#00000000</color>
2
  • how to change progress circle color
    – DkThakur
    Apr 28, 2017 at 10:05
  • 2
    To change color of circle of progress dialog you can use : 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();
    – Zafar Imam
    Oct 4, 2017 at 9:38
6

Just single line code :

pd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
4
  • 1
    How to get the circle in middle of the window?
    – hetsgandhi
    Oct 1, 2018 at 7:08
  • @hetsgandhi If you want to customize whole progress dialog then just extends Dialog and create your own view. By the way progress dialog is now deprecated.
    – SANAT
    Oct 11, 2018 at 6:48
  • So what should be used other than any library?
    – hetsgandhi
    Oct 11, 2018 at 7:31
  • @hetsgandhi Use ProgressBar. If you want to disable touch then you can set flags to window: window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) and enable touch using : window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
    – SANAT
    Oct 11, 2018 at 8:30

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.