SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE); pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86")); pDialog.setTitleText("Loading"); pDialog.setCancelable(false); pDialog.show();
只显示标题:
1 2 3 4
new SweetAlertDialog(this) .setTitleText("Here's a message!") .show();
显示标题和内容:
1 2 3 4 5
new SweetAlertDialog(this) .setTitleText("Here's a message!") .setContentText("It's pretty, isn't it?") .show();
显示异常样式:
1 2 3 4 5
new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE) .setTitleText("Oops...") .setContentText("Something went wrong!") .show();
显示警告样式:
1 2 3 4 5 6
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .show();
显示成功完成样式:
1 2 3 4 5
new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE) .setTitleText("Good job!") .setContentText("You clicked the button!") .show();
自定义头部图像:
1 2 3 4 5 6
new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE) .setTitleText("Sweet!") .setContentText("Here's a custom image.") .setCustomImage(R.drawable.custom_img) .show();
确认事件绑定:
1 2 3 4 5 6 7 8 9 10 11 12
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sDialog) { sDialog.dismissWithAnimation(); } }) .show();
显示取消按钮及事件绑定:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setCancelText("No,cancel plx!") .setConfirmText("Yes,delete it!") .showCancelButton(true) .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sDialog) { sDialog.cancel(); } }) .show();
确认后切换对话框样式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sDialog) { sDialog .setTitleText("Deleted!") .setContentText("Your imaginary file has been deleted!") .setConfirmText("OK") .setConfirmClickListener(null) .changeAlertType(SweetAlertDialog.SUCCESS_TYPE); } }) .show();
final SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE) .setTitleText("Loading"); pDialog.show(); pDialog.setCancelable(false); new CountDownTimer(800 * 7, 800) { public void onTick(long millisUntilFinished) { // you can change the progress bar color by ProgressHelper every 800 millis i++; switch (i) { case 0: pDialog.getProgressHelper() .setBarColor(getResources() .getColor(R.color.blue_btn_bg_color)); break; case 1: pDialog.getProgressHelper() .setBarColor(getResources() .getColor(R.color.material_deep_teal_50)); break; case 2: pDialog.getProgressHelper() .setBarColor(getResources() .getColor(R.color.success_stroke_color)); break; case 3: pDialog.getProgressHelper() .setBarColor(getResources() .getColor(R.color.material_deep_teal_20)); break;
case 4: pDialog.getProgressHelper() .setBarColor(getResources() .getColor(R.color.material_blue_grey_80)); break; case 5: pDialog.getProgressHelper() .setBarColor(getResources() .getColor(R.color.warning_stroke_color)); break;
case 6: pDialog.getProgressHelper() .setBarColor(getResources() .getColor(R.color.success_stroke_color)); break; } } public void onFinish() { i = -1; pDialog.setTitleText("Success!") .setConfirmText("OK") .changeAlertType(SweetAlertDialog.SUCCESS_TYPE); } }.start();