Custom Animation Dialog with full screen
1.Extends AlertDialog class like this
public class CustomAnimationDialog extends AlertDialog {
private AnimationDrawable mAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_custom_progress_dialog);
replaceAnimation();
}
public CustomAnimationDialog(Context context) {
super(context,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
}
private void replaceAnimation(){
replaceAnimation(this.findViewById(R.id.animation));
}
private void replaceAnimation(View imageView){
if(imageView == null){
return ;
}
imageView.setBackgroundResource(R.drawable.custom_animation_for_progress);
mAnimation = (AnimationDrawable) imageView.getBackground();
}
public static CustomAnimationDialog show(Context context, boolean cancelable) {
CustomAnimationDialog dialog = new CustomAnimationDialog(context);
dialog.setCancelable(cancelable);
dialog.show();
return dialog;
}
@Override
public void show() {
super.show();
if(mAnimation != null) {
mAnimation.start();
}
}
@Override
public void dismiss() {
super.dismiss();
if(mAnimation != null) {
mAnimation.stop();
}
}
}
2.add layout,view_custom_progress_dialog.xml
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@android:color/transparent"
>
<ImageView
android:id="@+id/animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
/>
</LinearLayout>
3.add drawable animation PNG ,custom_animation_for_progress.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/animation_01" android:duration="250" />
<item android:drawable="@drawable/animation_01_02" android:duration="250" />
<item android:drawable="@drawable/animation_01_03" android:duration="250" />
</animation-list>
4.Write UI Code in your MainActivity.java (any other main activity)
CustomAnimationDialog.show(this,true);
Done!