Put your gif image in /res/raw folder
In your class declare mProgressDialog
TransparentProgressDialog mProgressDialog;
then use following code to show progress dialog
if (mProgressDialog == null)
mProgressDialog = new TransparentProgressDialog(this);
if (mProgressDialog.isShowing())
mProgressDialog.dismiss();
mProgressDialog.setTitle(getResources().getString(R.string.title_progress_dialog));
mProgressDialog.setCancelable(false);
mProgressDialog.show();
Create a class TransparentProgressDialog where .gif can be loaded using Glide library.
public class TransparentProgressDialog extends Dialog {
private ImageView iv;
public TransparentProgressDialog(Context context) {
super(context, R.style.TransparentProgressDialog);
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER_HORIZONTAL;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(false);
setOnCancelListener(null);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
iv = new ImageView(context);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(iv);
Glide.with(context).load(R.raw.gif_loader).into(imageViewTarget);
layout.addView(iv, params);
addContentView(layout, params);
}
@Override
public void show() {
super.show();
}
}