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

SweetAlertDialog(sweet-alert-dialog)在github上的项目主页是:https://github.com/pedant/sweet-alert-dialog
需要注意的是,SweetAlertDialog(sweet-alert-dialog)作为库,其自身又依赖另外一个github上的开源库materialish-progress(其在github上的项目主页是:https://github.com/pnikosis/materialish-progress )。如果使用SweetAlertDialog(sweet-alert-dialog),则需要再把materialish-progress也导入到Eclipse中作为库被SweetAlertDialog(sweet-alert-dialog)引用。
下面是demo代码:
MainActivity.java:
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("It's pretty, isn't it?")
.show();
break;
case R.id.error_text_test:
new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE)
.setTitleText("Oops...")
.setContentText("Something went wrong!")
.show();
break;
case R.id.success_text_test:
new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("Good job!")
.setContentText("You clicked the button!")
.show();
break;
case R.id.warning_confirm_test:
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) {
// reuse previous dialog instance
sDialog.setTitleText("Deleted!")
.setContentText("Your imaginary file has been deleted!")
.setConfirmText("OK")
.setConfirmClickListener(null)
.changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
}
})
.show();
break;
case R.id.warning_cancel_test:
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) {
// reuse previous dialog instance, keep widget user state, reset them if you need
sDialog.setTitleText("Cancelled!")
.setContentText("Your imaginary file is safe :)")
.setConfirmText("OK")
.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("Deleted!")
.setContentText("Your imaginary file has been deleted!")
.setConfirmText("OK")
.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("Sweet!")
.setContentText("Here's a custom image.")
.setCustomImage(R.drawable.custom_img)
.show();
break;
case R.id.progress_dialog:
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();
break;
}
}
}
sample_activity.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="Try me!" /> <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="Try me!" /> <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="Try me!" /> <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="Try me!" /> <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="Try me!" /> <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="Try me!" /> <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="Try me!" /> <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="Try me!" />
</RelativeLayout> </ScrollView>
精美舒适的对话消息提示框--第三方开源--SweetAlertDialog的更多相关文章
- Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)
		
Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog) Android第三方开源对话消息提示框:SweetAlertDialog(sweet- ...
 - Android开发 ---构建对话框Builder对象,消息提示框、列表对话框、单选提示框、多选提示框、日期/时间对话框、进度条对话框、自定义对话框、投影
		
效果图: 1.activity_main.xml 描述: a.定义了一个消息提示框按钮 点击按钮弹出消息 b.定义了一个选择城市的输入框 点击按钮选择城市 c.定义了一个单选提示框按钮 点击按钮选择某 ...
 - 自定义iOS 中推送消息 提示框
		
看到标题你可能会觉得奇怪 推送消息提示框不是系统自己弹出来的吗? 为什么还要自己自定义呢? 因为项目需求是这样的:最近需要做 远程推送通知 和一个客服系统 包括店铺客服和官方客服两个模块 如果有新的消 ...
 - Android:Toast简单消息提示框
		
Toast是简单的消息提示框,一定时间后自动消失,没有焦点. 1.简单文本提示的方法: Toast.makeText(this, "默认的toast", Toast.LENGTH_ ...
 - 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
		
原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...
 - Android应用开发学习之Toast消息提示框
		
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来看Toast消息提示框的用法.使用Toast消息提示框一般有三个步骤: 1. 创建一个Toast对象.可 ...
 - JS~Boxy和JS模版实现一个标准的消息提示框
		
面向对象的封装 面向对象一个入最重要的特性就是“封装”,将一些没有必要公开的方法和属性以特定的方式进行组装,使它对外只公开一个接口,外界在调用它时,不需要关注它实现的细节,而只要关注它的方法签名即可, ...
 - MFC上下浮动与渐入渐出消息提示框实现
		
类似QQ与360软件,消息提示有两种.上下浮动.渐入渐出. 1.上下浮动提示框实现 机制,定时器响应上下浮动消息. 主要API:MoveWindow. 源码如下UpDownTipDlg.h.UpDow ...
 - Android消息提示框Toast
		
Android消息提示框Toast Toast是Android中一种简易的消息提示框.和Dialog不一样的是,Toast是没有焦点的,toast提示框不能被用户点击,而且Toast显示的时间有限,t ...
 
随机推荐
- 【Android 界面效果42】如何自定义字体
			
项目里要统一用设计师的字体,android:typeface只支持系统三种字体.有什么比较好的做法? 你需要为整个应用替换自定义字体. 解决方案 1)Android默认方法 #1 你可以通过ID查找到 ...
 - jQuery选择器之层次选择器Demo
			
测试代码: 02-层次选择器.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
 - GSS3 SPOJ 1716. Can you answer these queries III  gss1的变形
			
gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于 ...
 - canvas基础2--绘制图形
			
栅格 绘制矩形 不同于SVG,HTML中的元素canvas只支持一种原生的图形绘制:矩形.所有其他的图形的绘制都至少需要生成一条路径.不过,我们拥有众多路径生成的方法让复杂图形的绘制成为了可能. 首先 ...
 - 504 Gateway Time-out 和 502 Bad Gateway相关处理
			
若报:504 Gateway Time-out则与nginx有关 解决方案: #vim nginx.conf 添加以下代码: http{ fastcgi_connect_timeout 300; fa ...
 - 文件上传利器SWFUpload入门简易教程
			
凡做过网站开发的都应该知道表单file的确鸡肋. Ajax解决了不刷新页面提交表单,但是却没有解决文件上传不刷新页面,当然也有其它技术让不刷新页面而提交文件,该技术主要是利用隐藏的iFrame, 较A ...
 - WinForm打包后皮肤无效(解决方案)
			
今天在项目中用到了SkinEngine,遇到了一点问题,总结出点心得: 问题: 为什么我们在开发中皮肤还是显示的,但是打包后就没有效果了? 我也遇到了同样的问题,一开始以为是路径的问题: 我不知道大家 ...
 - SQL循环
			
加群学习:457351423 这里有4000多部学习视频,有需要的欢迎进群学习! declare @temp Table ( nf varchar(50), yf varchar(50), sm va ...
 - UILabel 整理
			
UILabel 多行文字自动换行 (自动折行) 1.UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 3 ...
 - Ueditor 1.4.3 单独调用上传图片,或文件功能
			
第一步, 引入文件 <script src="ueditor/ueditor.config.js" type="text/javascript" char ...