Skip to content

Instantly share code, notes, and snippets.

@rajohns08
Last active March 18, 2016 02:13
Show Gist options
  • Save rajohns08/e241e087d9a780e82eb6 to your computer and use it in GitHub Desktop.
Save rajohns08/e241e087d9a780e82eb6 to your computer and use it in GitHub Desktop.
Android - Custom progress dialog loading indicator utility class
public class MyProgressDialog {
private static ProgressDialog progressDialog;
public static void show(Context context, int messageResourceId) {
if (progressDialog != null) {
progressDialog.dismiss();
}
int style;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
style = android.R.style.Theme_Material_Light_Dialog;
} else {
//noinspection deprecation
style = ProgressDialog.THEME_HOLO_LIGHT;
}
progressDialog = new ProgressDialog(context, style);
progressDialog.setMessage(context.getResources().getString(messageResourceId));
progressDialog.setCancelable(false);
progressDialog.show();
}
public static void dismiss() {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment