25

I want to set the back ground to the transparent , so I have set the following code in

styles.xml
<style name="dialog" parent="@android:style/Theme.Dialog">  
            <item name="android:windowFrame">@null</item>  
            <item name="android:windowIsFloating">true</item>  
            <item name="android:windowContentOverlay">@null</item>  
            <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>  
            <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>  
            <item name="android:windowBackground">@android:color/transparent</item>  
            <item name="android:windowNoTitle">true</item> 
        </style> 

And I have use the Progressdialog like the following code in JAVA file and in fragment.

Activity activity = getActivity() ;
mProgressDialog = new ProgressDialog(activity,R.style.dialog) ;
mProgressDialog.setCancelable(false) ;
mProgressDialog.show() ;

But I get the progress like the following picture , and it doesn't has transparent background.

enter image description here

Why the background doesn't change to the transparent ?

Martin
  • 2,813
  • 11
  • 43
  • 66
  • possible duplicate of [Create a progressDialog only with the spinner (in the middle)](http://stackoverflow.com/questions/21751662/create-a-progressdialog-only-with-the-spinner-in-the-middle) –  Sep 18 '15 at 13:51
  • **See also** [Dialog with transparent background in Android](https://stackoverflow.com/questions/10795078/dialog-with-transparent-background-in-android) – Top-Master May 30 '22 at 18:48

5 Answers5

71

create custom MyTheme in values\styles.xml

<style name="MyTheme" parent="android:Theme.Holo.Dialog">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:windowBackground">@android: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 CustomAlertDialogStyle in values\styles.xml

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

And set ProgressDialog like:

 pd = new ProgressDialog(getActivity(),R.style.MyTheme);
 pd.setCancelable(false);
 pd.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
 pd.show();
Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130
M D
  • 47,665
  • 9
  • 93
  • 114
  • @Simple Plan , i'm sorry to bother you, but is there a way to change the progress widget via style ? – elmorabea Jun 05 '14 at 10:37
  • #M D, Is it possible to change its (progress bar) position with respect to other elements ? Currently its center align both vertically & horizontally. – Mohit Mar 11 '15 at 12:10
  • @Mohit I am not trying this but you can set Gravity in your style . – M D Mar 11 '15 at 12:12
  • 2
    Tried but no success ! Apart from this, nice solution. – Mohit Mar 11 '15 at 12:33
  • 1
    Thanks. Also you may add to a style a following line: @android:style/Widget.Holo.Light.ProgressBar.Large in order to make it large. – CoolMind Dec 24 '15 at 09:27
12

You can use this code,work fine in devices >= 19 (Kitkat)

progress = ProgressDialog.show(Splash.this, null, null, true);
            progress.setContentView(R.layout.elemento_progress_splash);
            progress.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

            //progress.show();

enter image description here

David Hackro
  • 3,652
  • 6
  • 41
  • 61
7

Try this

mProgressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

EDIT:

Try adding this to the layout xml

        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:background">@android:color/transparent</item>
AndyFaizan
  • 1,833
  • 21
  • 30
1

Just try this. It's working for me.

In styles.xml

<style name="TransparentProgressDialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:background">@android:color/transparent</item>

  </style>

In Activity/Fragment:

ProgressDialog pDialog = new ProgressDialog(this, R.style.TransparentProgressDialog);
Nanda Gopal
  • 2,519
  • 1
  • 17
  • 25
0

In my case, i just define at color.xml the variables

For light style: <color name="accent_material_light">#000000</color>

For dark style: <color name="accent_material_dark">#000000</color>

These changes affect the whole system