Android : How to get rid of weird border around progress dialog
Asked Answered
P

5

9

I have made my custom style for progress dialog, however it has weird borders around it.

progress dialog

Here is the theme:

<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">@android:color/white</item>
    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="android:background">@color/colorPrimaryDark</item>
    <item name="android:popupBackground">@null</item>
</style>

Any ideas why there is such weird background ?

Peake answered 30/11, 2015 at 20:15 Comment(3)
it's progress dialog and not AlertDialog.Peake
Remove <item name="android:background">@color/colorPrimaryDark</item>. It's not the correct way to set the background drawable for a ProgessDialogObel
@JaredRummler But then it's just whit, and also with white ugly borders. How to get desired blue look correctly?Peake
C
8

To remove the colored or white border around the progress dialog have the dialog use a theme that defines a transparent windowBackground

<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>

When creating the dialog use this theme:

new ProgressDialog(MyActivity.this, R.style.MyDialogTheme);
Counteraccusation answered 20/4, 2016 at 19:5 Comment(0)
O
2

Please add:

your_progress_dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

to your java.

Hope this helps!

Orlena answered 30/11, 2015 at 20:18 Comment(4)
What android version are you developing for?Orlena
Android 4.4 api level 19Peake
Please add <item name="android:windowBackground">@android:color/transparent</item> to your styles.Orlena
still same weird borderPeake
H
1

it's related to this question. But in contrary to alert dialog there is no AppCompat support to ProgressDialog. I didn't manage to solve the problem , its possible to use the deprected THEME_HOLO_LIGHT

ProgressDialog dialog= new ProgressDialog(this,ProgressDialog.THEME_HOLO_LIGHT);

but you loose all the benefits of AppCompat (like color accent).

Henryk answered 27/11, 2016 at 9:59 Comment(1)
Thanks, this was the quickest fix and does actually work (unlike some other answers here). I use it only when Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT.Metapsychology
G
0

Create Two Style

1) API Level less then equal 19

  <style name="AppAlertTheme19" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/btngreen</item>
        <item name="android:textColorPrimary">@color/transparent</item>
        <item name="android:background">@color/transparent</item>
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:popupBackground">@null</item>
    </style>

2) API Level greater than 19

<style name="AppAlertTheme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/btngreen</item>
        <item name="android:textColorPrimary">@color/transparent</item>
        <item name="android:background">@color/white</item>
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:popupBackground">@null</item>
    </style>

3)and init progress view like this

public class ProgressDialogCustom extends ProgressDialog {
    public ProgressDialogCustom(Context context) {
        super(context, getStyle());
        setMessage("Please Wait ...");
        setCancelable(false);
    }

    private static int getStyle() {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
            return R.style.AppAlertTheme;
        } else {
            return R.style.AppAlertTheme19;
        }
    }
}
Geodynamics answered 9/2, 2017 at 9:40 Comment(0)
D
0

I may be late to answer this question, but as I was facing same problem, I resolved it as follows:
I created 2 styles one for above lollipop and one for below it.

API Level greater than 19

<style name="AppAlertTheme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/white</item>
        <item name="android:textColorPrimary">@color/transparent</item>
        <item name="android:background">@color/blue</item>
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:popupBackground">@null</item>
</style>

API Level less than 19

<style name="AppAlertTheme_api19" parent="android:Theme.Holo.Dialog">
     <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:windowBackground">@color/nlue</item>
    <item name="android:background">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:textColor">@color/white</item>
</style>

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

Then used this style as follows:

public int getProgressDailogStyle(){
  if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
      return R.style.AppAlertTheme;
  } else {
      return R.style.AppAlertTheme_api19;
  }
}

and finally

   progressDialog = new ProgressDialog(context, getProgressDailogStyle());

Hope this helps you..

Dinodinoflagellate answered 7/6, 2017 at 6:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.