Custom Progress Dialog Box

I created a Custom ProgressDialog as follows: First I have an Animation List with 9 consecutive Imges

<?xml version="1.0" encoding="utf-8"?> 

 <item android:drawable="@drawable/icon_progress_dialog_drawable_1" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_2" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_3" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_4" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_5" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_6" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_7" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_8" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_9" android:duration="150" /> 

Then I have my own style

  <style name="CustomDialog" parent="@android:style/Theme.Dialog" > <item name="android:windowFrame">@null</item> <item name="android:windowBackground">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowTitleStyle">@null</item> <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:gravity">center</item> <item name="android:minHeight">70dip</item> <item name="android:maxHeight">80dip</item> 

Now in code, I call it like this

  dialog = new ProgressDialog(KaguaHome.this); dialog.setProgressStyle(R.style.CustomDialog); dialog.setIndeterminate(true); dialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progress_dialog_icon_drawable_animation)); dialog.show(); 

As a result enter image description here

However, I want to achieve progress dialogs with only an image (no white background), and it should be centered, what should I change?

+4
android progressdialog
Jun 19 '13 at 7:21
source share
2 answers

Try it and tell me how it works. I tried it, and for me it happens in the center.

 <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:background">@android:color/transparent</item> <item ame="android:indeterminateDrawable">@anim/progress_dialog_icon_drawable_animation</item> </style> 

And declare it as

customDialog = new dialog (getActivity (), R.style.NewDialog);

See if this works.

+5
Jun 19 '13 at 7:46
source share
  Dialog dialog = new Dialog(FlashActivity.this, android.R.style.Theme_Dialog); dialog.setCancelable(false); ImageView imageView = new ImageView(this); imageView.setScaleType(ScaleType.FIT_XY); imageView.setBackgroundResource(R.drawable.progress_dialog_icon_drawable_animation); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(imageView); dialog.setCanceledOnTouchOutside(false); dialog.getWindow().setBackgroundDrawable(getResources().getDrawable(R.drawable.color_drawable_1)); dialog.show(); AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground(); animationDrawable.start(); 

Below is color_drawable_1

  <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@color/transparent"></item> </selector> 

Below is transparent in colors.xml (you can put any transparent color here)

  <?xml version="1.0" encoding="utf-8"?> <resources> <color name="transparent">#00ffffff</color> </resources> 

Below is your progress_dialog_icon_drawable_animation

  <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/icon_progress_dialog_drawable_1" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_2" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_3" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_4" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_5" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_6" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_7" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_8" android:duration="150" /> <item android:drawable="@drawable/icon_progress_dialog_drawable_9" android:duration="150" /> </animation-list> 

Since you are creating a custom dialog, do not create the dialog as an instance of progressdialog. Create an instance of the dialog box. Add an image to your view. Adjust the image with the ability to draw and start the animation. Now you need to change the windows dialog as you need. Do it like no headline, because the dialogue topic usually has a headline, and you must set its background color with any transparent color.

Try the above and you can tell me about any problems. He works.

+1
Nov 08 '14 at 19:22
source share



All Articles