Reputation: 1009
I have made my custom style for progress dialog, however it has weird borders around it.
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 ?
Upvotes: 9
Views: 2655
Reputation: 3843
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..
Upvotes: 0
Reputation: 532
Create Two Style
<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>
<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>
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;
}
}
}
Upvotes: 0
Reputation: 81
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).
Upvotes: 1
Reputation: 81
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);
Upvotes: 8
Reputation: 1242
Please add:
your_progress_dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
to your java.
Hope this helps!
Upvotes: 2