Centering Custom Progress Dialog
Asked Answered
W

2

4

I have created a Custom ProgressDialog as follows: First I have an Animation List with 9 sequential 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 a custom 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 as follows

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

The result is enter image description here

I however want to achieve a progress Dialog with only the image (No white background) and It should be centered,what should I modify?

Wallacewallach answered 19/6, 2013 at 7:21 Comment(5)
I would do it as activity, If you are interested in I can make sample codeBlueberry
I dont want it done programatically...Need it via Style and anim InsteadWallacewallach
Yeah but IMHO if you want only one object on youd dialog what is more.. you want also place it in the center.. I think activity with dialog's style would be the best solutionBlueberry
@akajaymo : Did my answer work for you with styles and anim.Leucoplast
I have written my findings below your anwserWallacewallach
L
5

Try this and say how this works. I have tried this and for me it comes at 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 this as

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

See if this works.

Leucoplast answered 19/6, 2013 at 7:46 Comment(2)
I have tried your solution,I get the progress Dialog in the Middle,however its not the custom one, its the default (Centered and with a black Background)Wallacewallach
<item name="android:backgroundDimEnabled">true</item> make it falseBlueberry
D
1
    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();

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

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

The 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 custom dialog do not create dialog as an instance of progressdialog. Create an instance of Dialog using dialog theme. Add image view to its view content. Set your drawable to image view and start the animation. Now you have to modify the windows dialog as you required. Make it as no title because dialog theme generally comes with title and you have to set its background color with any transparent color

Try the above and you can let me know any issues. It works.

Divot answered 8/11, 2014 at 19:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.