5

I am working on Custom Progress Dialog. I've set its style like done in this SO question Positionning the spinning wheel in a custom progress dialog My progress dialog is showing no animation at all. When I changed the background to black then it was only showing a black box. I want my progress dialog to animate.

In activity I am doing something like this

 public MyProgressDialog(Context context) {
        super(context, R.style.NewDialog);
    }

and the NewDialog is as:

<style name="NewDialog" parent="@android:style/Theme.Dialog">

    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:width">50dip</item>
    <item name="android:height">50dip</item>
    <item name="android:background">@android:color/transparent</item>

</style>

Any help is appreciated in advance

Community
  • 1
  • 1
Najeebullah Shah
  • 4,124
  • 3
  • 33
  • 46

2 Answers2

11
import android.app.ProgressDialog;
import android.content.Context;
import android.view.animation.Animation;

public class MyProgressDialog extends ProgressDialog {

    public MyProgressDialog(Context context) {
        super(context,R.style.NewDialog);

        // TODO Auto-generated constructor stub
    }

}

//RESOURCE STYLE FILE res->values->mydialog.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <style name="NewDialog" parent="@android:style/Theme.Dialog">

    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:colorBackground">#ffffff</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:width">600dip</item>
    <item name="android:height">100dip</item>
     <item name="android:textColor">#FF0000</item>

</style>
</resources>

//AND USE THIS CODE ANYWHERE IN YOUR APPLICATION TO GET CUSTOM PROGRESS DIALOG

MyProgressDialog pd = new MyProgressDialog(YouActivity.this);
pd.setMessage("Loading. Please wait...");
pd.show();

Well there isn't any difference in your code and mine as I have run your code just to test whether you are experiencing any problem or not but still I am posting for you so that you can sought out the problem.

Thanks :)

SALMAN
  • 3,909
  • 1
  • 24
  • 21
  • one little difference @SALMAN I was extending MyProgressDialog with Dialog, and in your case its ProgressDialog. Still having an issue the progress dialog is not centred in the box it is lying, any clue – Najeebullah Shah Jul 25 '12 at 06:19
  • Change these two lines in style file. 20dip 20dip – SALMAN Jul 25 '12 at 07:31
  • Salman: i want something like in this link http://stackoverflow.com/questions/3225889/how-to-center-progress-indicator-in-progressdialog-easily-when-no-title-text-pa the progress indicator is not in the center of the dialog – Najeebullah Shah Jul 25 '12 at 07:59
2
public class TransparentProgressDialog extends Dialog {

 private ImageView iv;

 public TransparentProgressDialog(Context context, int resourceIdOfImage) {

     super(context, R.style.TransparentProgressDialog);
  WindowManager.LayoutParams wlmp = getWindow().getAttributes();
  wlmp.gravity = Gravity.CENTER_HORIZONTAL;
  getWindow().setAttributes(wlmp);
  setTitle(null);
   setCancelable(false);
   setOnCancelListener(null);
   resourceIdOfImage = R.drawable.loading_spinner_icon;
  LinearLayout layout = new LinearLayout(context);
   layout.setOrientation(LinearLayout.VERTICAL);
  LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
   LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  iv = new ImageView(context);
  iv.setImageResource(resourceIdOfImage);
  layout.addView(iv, params);
  addContentView(layout, params);
  }

  }

You will get complete example with animation HERE