Why is the ProgressDialog background not set to transparent?

I want to set the back panel to transparent, so I installed 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 use Progressdialog as the following code in the JAVA file and in fragment .

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

But I get progress, as in the following figure, and it does not have a transparent background.

enter image description here

Why doesn't the background change to transparent?

+22
android android-styles progressdialog
Feb 22 '14 at 16:49
source share
4 answers

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 to 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 the ProgressDialog as:

  pd = new ProgressDialog(getActivity(),R.style.MyTheme); pd.setCancelable(false); pd.setProgressStyle(android.R.style.Widget_ProgressBar_Small); pd.show(); 
+64
Feb 22 '14 at 17:01
source share

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

+11
Jan 18 '16 at 20:03
source share

try it

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

EDIT:

Try adding this to your xml layout

  <item name="android:backgroundDimEnabled">true</item> <item name="android:background">@android:color/transparent</item> 
+5
Feb 22 '14 at 16:55
source share

In my case, I just define variables in color.xml

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

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

These changes affect the entire system.

0
Jul 11 '17 at 17:03
source share



All Articles