Centering Custom Progress Dialog

回眸只為那壹抹淺笑 提交于 2019-11-28 02:02:20

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.

    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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!