waqas
waqas

Reputation: 342

Using custom ProgressDialog android

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.

Upvotes: 19

Views: 72381

Answers (8)

RochaaP
RochaaP

Reputation: 315

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.

Upvotes: 0

Deepak gupta
Deepak gupta

Reputation: 947

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

Upvotes: 8

Tsar
Tsar

Reputation: 63

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

Upvotes: 1

Ojonugwa Jude Ochalifu
Ojonugwa Jude Ochalifu

Reputation: 27237

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

Upvotes: 28

Alaa M.
Alaa M.

Reputation: 5273

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>

Upvotes: 1

ajmal
ajmal

Reputation: 11

Add this on style

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

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

Upvotes: 1

Khawar
Khawar

Reputation: 859

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

Upvotes: 17

NAP-Developer
NAP-Developer

Reputation: 3796

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

 progressDialog = new ProgressDialog(Activity.this,R.style.CustomDialog);

Upvotes: 2

Related Questions