Using custom ProgressDialog android
Asked Answered
P

8

19

I am using custom ProgressDialog in my application, I am able to make it custom but I also want to remove the upper border or window of progressDialog. In styles.xml I define customDialog as

<style name="AppTheme" parent="android:Theme.Light" />

<style name="CustomDialog" parent="@android:style/Theme.Dialog">
    <item name="android:background">#7BC047</item>
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:windowBackground">@null</item>
     <item name="android:windowFrame">@null</item>
</style>

For removing the parent window I am setting windowBackground to null and windowFrame to null but it did't work for me. Currently my custom progress dialog look like that in the image given belowenter image description here

I am using this code to set the style of progressDialog.

 private void showProgressDialog() {
    progressDialog = new ProgressDialog(this,R.style.CustomDialog);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage("Logging in. Please wait.");
    progressDialog.show();
}

So,help me regarding this issue any help should be really appreciated.

Pent answered 17/12, 2012 at 7:33 Comment(1)
Look at this answer.Plethoric
B
28

This answer does not address the problem stated in the question, but when searching for how to implement a custom progress dialog, this is the only link pointing to SO. That said, I found a cool and easy-to -use custom progress dialog by a certain Maksym Dybarskyi on this link.

All Credit goes to the creator, not me.Am just sharing

All you need to do is add this to your dependencies:

dependencies {
...
   compile 'com.github.d-max:spots-dialog:0.4@aar'
}

And then the custom style:

<style name="Custom" parent="android:Theme.DeviceDefault.Dialog">
    <item name="DialogTitleAppearance">@android:style/TextAppearance.Medium</item>
    <item name="DialogTitleText">Please Wait</item>
    <item name="DialogSpotColor">@android:color/holo_orange_dark</item>
    <item name="DialogSpotCount">8</item>
</style>

Finally, in your code do this:

private AlertDialog progressDialog;
progressDialog = new SpotsDialog(mContext, R.style.Custom);

//Am using it in an AsyncTask. So in  my onPreExecute, I do this:
public void onPreExecute() {
  super.onPreExecute();
  progressDialog.show();
  ...
 }

//dismiss in onPostExecute
public void onPostExecute(){
   progressDialog.dismiss();
 } 

Result:

enter image description here

The yellow dots move from left to right and you can change the number of dots in styles

Barbiebarbieri answered 8/9, 2015 at 7:6 Comment(4)
Is there any way to change background of alert dialog by using this library?Menadione
Yes. @GuruprasadRao check Khawar's answer belowDetainer
<item name="android:windowBackground">@color/transparent</item> add this is styleDetainer
do not forget to add the following to Proguard , otherwise the dots will not appear in the signed APK -keep class dmax.dialog.** { *; }Reahard
H
17

I know I'm quite late to answer but I'll answer any way,

Dialog dialog = new  Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_login);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Hindoo answered 28/4, 2013 at 10:35 Comment(0)
C
8

I'm using custom ProgressDialog in my application . For that we have to follow some steps this are as follow.

step-1 Create a xml layout custom_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:padding="@dimen/dp_size_10"
    android:layout_height="match_parent">
<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:indeterminateTint="@color/colorPrimary"
    android:layout_centerInParent="true"/>
</RelativeLayout>

step-2 Create a java file for this custom dialog.

package com.example.customeprogress;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

public class CustomProgressDialogue extends Dialog {
    public CustomProgressDialogue(Context context) {
        super(context);

        WindowManager.LayoutParams wlmp = getWindow().getAttributes();

        wlmp.gravity = Gravity.CENTER_HORIZONTAL;
        getWindow().setAttributes(wlmp);
        setTitle(null);
        setCancelable(false);
        setOnCancelListener(null);
        View view = LayoutInflater.from(context).inflate(
                R.layout.custom_progress, null);
        setContentView(view);
    }
}

step-3 Create a object of this custom class in your activity java class and initialised it as follow use the object for show() or dismiss()

CustomProgressDialogue object=new CustomProgressDialogue(this);

and show this dialog using.

object.show(); and dismissed it using object.dismiss();

Result of output. see out put here

Casual answered 25/3, 2019 at 18:8 Comment(2)
Thank you @Deepak guptaHarewood
This is the exact solution i was looking for. It also helps managing height and width of Alert dialog. ThanksGarber
H
2

Just check for using activity name in your constructor of progress dialog,

 progressDialog = new ProgressDialog(Activity.this,R.style.CustomDialog);
Hayfork answered 17/12, 2012 at 10:13 Comment(0)
O
1

Add this on style

<item name="android:background">@android:color/transparent</item>

<item name="android:windowBackground">@android:color/transparent</item>
Outdated answered 20/8, 2014 at 6:26 Comment(1)
Your answer seems to trivial. Please be more descriptive on what you proposing to do.Ultrastructure
H
1

Add this to your CustomDialog in styles.xml:

<item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>

And this 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>
Heshvan answered 1/8, 2015 at 16:4 Comment(0)
G
1
<style name="CustomDialog" parent="Theme.AppCompat.Light.Dialog">
   <item name="android:background">#7BC047</item>
   <item name="android:textColor">#FFFFFF</item>
   <item name="android:windowBackground">@color/colorTransparent</item>
</style>

This did the job for me.

Gruelling answered 11/12, 2018 at 12:19 Comment(0)
K
0

This might not be a suitable answer for the above question. But this is interesting and I thought to add here.

(I cannot comment with my current reputation)

Check this link

The original author is adding a gif instead of default loading dialog and I think if there is an improvement then it would be nice replacement.

Kathernkatheryn answered 20/6, 2019 at 5:53 Comment(2)
Please add content of link to your answerBiotechnology
I already added it. Does it not visible to others.. :| LInkKathernkatheryn

© 2022 - 2024 — McMap. All rights reserved.