0

I want to make ProgressDialog Transparent but I never became Transparent It became Black background in ProgressDialog.How can I do that Kindly help

here is my code for ProgressDialog:-

private class LoginAttempt extends AsyncTask<String, Void, String> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(getActivity(), R.style.MyTheme);
        pDialog.setCancelable(false);
        pDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
        pDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        pDialog.show();

    }

here is my style.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

<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 here is my result:- enter image description here

Raj
  • 41
  • 2
  • 7

4 Answers4

2

This works for me (Assuming I am in MainActivity) :

    ProgressDialog pDialog = new ProgressDialog(MainActivity.this, R.style.AppTheme);
    pDialog.setCancelable(false);
    pDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
    pDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    pDialog.show();

OR, if I just do

 ProgressDialog pDialog = new ProgressDialog(MainActivity.this);

i.e. without supplying any theme, it works.

So turns out there's a problem in the theme that you are supplying. Try once without supplying the theme.

Yash
  • 5,225
  • 4
  • 32
  • 65
1

If you are taking <item name="android:windowBackground">@color/transparent</item> you have to define color in your color.xml for full transparency. like this:

<color name="transparent">#00FFFFFF</color>

Look here for reference:Transparent ARGB hex value

Community
  • 1
  • 1
Android Geek
  • 8,956
  • 2
  • 21
  • 35
0

First, define your object:

    private static ProgressDialog mProgressDialog;

Then create the method to run your progress dialog that includes the transparent background as below:

    public static void showSimpleProgressDialog(Context context, String title, String msg, boolean isCancelable) {
    try {
        if (mProgressDialog == null) {
            mProgressDialog = ProgressDialog.show(context, title, msg);
            mProgressDialog.setCancelable(isCancelable);
            mProgressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        }
        if (!mProgressDialog.isShowing()) {
            mProgressDialog.show();
        }

    } catch (IllegalArgumentException ie) {
        ie.printStackTrace();
    } catch (RuntimeException re) {
        re.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

You can then call this method from your activity as:

showSimpleProgressDialog(this, "Your Title", "Your Message", false);
Kizito Ikapel
  • 69
  • 1
  • 6
0

Use this in style file

    <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>

<style name="MyTheme" parent="android:Theme.Holo.Dialog">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:indeterminateTint">@color/colorPrimary</item>
</style>

and this for calling progress dialog :

       ProgressDialog progressDialog = new ProgressDialog(context,R.style.MyTheme);
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    progressDialog.setMessage("");
    progressDialog.show();
Rohit Lalwani
  • 529
  • 7
  • 14