Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)

Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)是一个套制作精美、动画效果出色生动的Android对话、消息提示框.

Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)-LMLPHP

需要两个lib包,其中一个依赖另一个,下载地址是:点此下载

 package cn.pedant.SweetAlert.sample;

 import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View; import cn.pedant.SweetAlert.SweetAlertDialog; public class SampleActivity extends Activity implements View.OnClickListener { private int i = -1; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_activity);
findViewById(R.id.basic_test).setOnClickListener(this);
findViewById(R.id.under_text_test).setOnClickListener(this);
findViewById(R.id.error_text_test).setOnClickListener(this);
findViewById(R.id.success_text_test).setOnClickListener(this);
findViewById(R.id.warning_confirm_test).setOnClickListener(this);
findViewById(R.id.warning_cancel_test).setOnClickListener(this);
findViewById(R.id.custom_img_test).setOnClickListener(this);
findViewById(R.id.progress_dialog).setOnClickListener(this);
} @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.basic_test:
// default title "Here's a message!"
SweetAlertDialog sd = new SweetAlertDialog(this);
sd.setCancelable(true);
sd.setCanceledOnTouchOutside(true);
sd.show();
break;
case R.id.under_text_test:
new SweetAlertDialog(this).setContentText("我很漂亮,是不是啊!").show();
break;
case R.id.error_text_test:
new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE).setTitleText("Oops...").setContentText("某些地方出错了!")
.show();
break;
case R.id.success_text_test:
new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE).setTitleText("好工作!").setContentText("来点击这个按钮!")
.show();
break;
case R.id.warning_confirm_test:
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE).setTitleText("你确定吗?").setContentText("你确定要删除它吗!")
.setConfirmText("是的,删除!").setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sDialog) {
// reuse previous dialog instance
sDialog.setTitleText("删除!").setContentText("你的文件已经删除了!").setConfirmText("好的")
.setConfirmClickListener(null).changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
}
}).show();
break;
case R.id.warning_cancel_test:
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE).setTitleText("你确定吗?").setContentText("是否删除文件!")
.setCancelText("不,退出!").setConfirmText("是的,删除!").showCancelButton(true)
.setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sDialog) {
// reuse previous dialog instance, keep widget user
// state, reset them if you need
sDialog.setTitleText("Cancelled!").setContentText("你的文件安全:)").setConfirmText("好的")
.showCancelButton(false).setCancelClickListener(null).setConfirmClickListener(null)
.changeAlertType(SweetAlertDialog.ERROR_TYPE); // or you can new a SweetAlertDialog to show
/*
* sDialog.dismiss(); new
* SweetAlertDialog(SampleActivity.this,
* SweetAlertDialog.ERROR_TYPE)
* .setTitleText("Cancelled!") .setContentText(
* "Your imaginary file is safe :)")
* .setConfirmText("OK") .show();
*/
}
}).setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sDialog) {
sDialog.setTitleText("删除了!").setContentText("你的文件被删除了!").setConfirmText("好的")
.showCancelButton(false).setCancelClickListener(null).setConfirmClickListener(null)
.changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
}
}).show();
break;
case R.id.custom_img_test:
new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE).setTitleText("很漂亮!")
.setContentText("这是一张图片.").setCustomImage(R.drawable.custom_img).show();
break;
case R.id.progress_dialog:
final SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE)
.setTitleText("载入中");
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("成功了!").setConfirmText("好的").changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
}
}.start();
break;
}
}
}

xml文件:

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF" > <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp" > <ImageView
android:id="@+id/logo_img"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="10dp"
android:contentDescription="@string/app_name"
android:src="@drawable/logo_big" /> <TextView
android:id="@+id/txt_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/logo_img"
android:layout_below="@id/logo_img"
android:layout_marginLeft="15dp"
android:text="show material progress"
android:textColor="#797979"
android:textSize="14sp" /> <Button
android:id="@+id/progress_dialog"
style="@style/dialog_blue_button"
android:layout_below="@id/txt_0"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="点击!" /> <TextView
android:id="@+id/txt_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/logo_img"
android:layout_below="@id/progress_dialog"
android:layout_marginLeft="15dp"
android:text="A basic message"
android:textColor="#797979"
android:textSize="14sp" /> <Button
android:id="@+id/basic_test"
style="@style/dialog_blue_button"
android:layout_below="@id/txt_1"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="点击!" /> <TextView
android:id="@+id/txt_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/logo_img"
android:layout_below="@id/basic_test"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="A title with a text under"
android:textColor="#797979"
android:textSize="14sp" /> <Button
android:id="@+id/under_text_test"
style="@style/dialog_blue_button"
android:layout_below="@id/txt_2"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="点击!" /> <TextView
android:id="@+id/txt_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/logo_img"
android:layout_below="@id/under_text_test"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="show error message"
android:textColor="#797979"
android:textSize="14sp" /> <Button
android:id="@+id/error_text_test"
style="@style/dialog_blue_button"
android:layout_below="@id/txt_3"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="点击!" /> <TextView
android:id="@+id/txt_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/logo_img"
android:layout_below="@id/error_text_test"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="A success message"
android:textColor="#797979"
android:textSize="14sp" /> <Button
android:id="@+id/success_text_test"
style="@style/dialog_blue_button"
android:layout_below="@id/txt_4"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="点击!" /> <TextView
android:id="@+id/txt_5"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/logo_img"
android:layout_below="@id/success_text_test"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="A warning message, with a listener bind to the Confirm-button..."
android:textColor="#797979"
android:textSize="14sp" /> <Button
android:id="@+id/warning_confirm_test"
style="@style/dialog_blue_button"
android:layout_below="@id/txt_5"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="点击!" /> <TextView
android:id="@+id/txt_6"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/logo_img"
android:layout_below="@id/warning_confirm_test"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="A warning message, with listeners bind to Cancel and Confirm button..."
android:textColor="#797979"
android:textSize="14sp" /> <Button
android:id="@+id/warning_cancel_test"
style="@style/dialog_blue_button"
android:layout_below="@id/txt_6"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="点击!" /> <TextView
android:id="@+id/txt_7"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/logo_img"
android:layout_below="@id/warning_cancel_test"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="A message with a custom icon"
android:textColor="#797979"
android:textSize="14sp" /> <Button
android:id="@+id/custom_img_test"
style="@style/dialog_blue_button"
android:layout_below="@id/txt_7"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="点击!" />
</RelativeLayout> </ScrollView>
04-25 04:20