Progress dialogue has white background on Lollipop Devices ,
Asked Answered
U

4

7

I am migrating my application on Android 5.0 i.e. Lollipop devices , I have problem regarding progress dialog , It work perfectly on pre lollipop devices , but on lollipop it has white background as shown in image enter image description here

But in pre lollipop devices it is of transparent background enter image description here

Below is my code :

progress.xml in layout

<?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:background="@android:color/transparent" >


<ProgressBar
        android:id="@+id/progressBar3"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:background="@android:color/transparent"
        android:layout_centerHorizontal="true"

        android:indeterminate="true"
        android:indeterminateDrawable="@drawable/myprogress"
        android:minHeight="48dp" />
   </RelativeLayout>

myprogress.xml in drawable

<shape
    android:shape="oval"
    android:useLevel="false" >
    <size
        android:height="48dip"
        android:width="48dip" />

    <gradient
        android:centerColor="#ff001100"
        android:centerY="0.50"
        android:endColor="#ffffffff"
        android:startColor="#ff000000"
        android:type="sweep"
        android:useLevel="false" />
</shape>

and in Java i am using like this

public ProgressDialog mProgressDialog;

  if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.cancel();
        }

        mProgressDialog = new ProgressDialog(context);
        mProgressDialog.setCancelable(false);

        mProgressDialog.show();
        mProgressDialog.setContentView(R.layout.progress);
Uncommercial answered 19/5, 2015 at 6:19 Comment(2)
change you app theme in the style.xml to a dark theme and dialogs should be darkTimeous
i dont want dark dilaog , I want that white background as transparentUncommercial
U
1

I solved this problem with help of this tutorial http://www.techrepublic.com/blog/software-engineer/create-a-transparent-progress-dialog-on-android/

I just pass my drawable into this code

mProgressDialog = new TransparentProgressDialog(context, **R.drawable.progress**);
        mProgressDialog.setCancelable(false);

and rest code is same as in this example.

Uncommercial answered 27/5, 2015 at 10:46 Comment(0)
P
5

Issue was a white background on lollipop.

solution either of the two (both are same though):

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

or

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Publia answered 16/9, 2015 at 16:20 Comment(0)
C
2

Looks like you have a solution now, but if anyone else is experiencing a similar issue; I found that overriding the ProgressDialog's theme in the constructor worked for me. Something like:

mProgressDialog = new ProgressDialog(context, ProgressDialog.THEME_HOLO_LIGHT);
Crispi answered 30/7, 2015 at 12:11 Comment(1)
This works but THEME.HOLO.LIGHT is deprecated. Is there an alternative?Socialite
S
2

You can also create a style and assign the style to the dialog:

    ProgressDialog dialog = new ProgressDialog(context, R.style.ProgressDialogStyle);

The style (in style.xml):

<style name="ProgressDialogStyle" parent="android:Theme.Holo.Light.Dialog">
    <item name="android:windowBackground">@color/color_transparent</item>
</style>
Sole answered 7/10, 2016 at 16:54 Comment(0)
U
1

I solved this problem with help of this tutorial http://www.techrepublic.com/blog/software-engineer/create-a-transparent-progress-dialog-on-android/

I just pass my drawable into this code

mProgressDialog = new TransparentProgressDialog(context, **R.drawable.progress**);
        mProgressDialog.setCancelable(false);

and rest code is same as in this example.

Uncommercial answered 27/5, 2015 at 10:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.