漂亮的对话框 sweet-alert-dialog

项目地址: https://github.com/pedant/sweet-alert-dialog

android原生的dialog太生硬了,之前看到了这个效果非常不错但是没有用过,今天给别人推荐使用,他遇到了问题,导入后错误非常多,也没有库工程。于是自己认真看了一下,这是个AndroidStudio的工程,并且里面还依赖于materialish-progress工程,也是个AS的工程。于是打算弄一个eclipse的版本并且将这两个工程融合在一起作为一个库工程XAlertDialogLibrary。使用时将其作为库导入项目中即可。

效果如下

使用起来非常简单,测试代码如下:

MainActivity.java

    public class MainActivity extends Activity implements View.OnClickListener {  

        private int i = -1;  

        @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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;
}
}
}

activity_main.xml

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

XAlertDialogLibrary(eclipse):点此下载

来自:http://blog.csdn.net/cauchyweierstrass/article/details/46335143

android漂亮的对话框项目sweet-alert-dialog的更多相关文章

  1. <Android 基础(十五)> Alert Dialog

    介绍 The AlertDialog class allows you to build a variety of dialog designs and is often the only dialo ...

  2. 好看的dialog,sweet Alert Dialog 导入Android Studio

    系统自带的dialog实在是丑到无法忍受.所以找到了一款比较好的第三方dialog. github 地址如下:https://github.com/pedant/sweet-alert-dialog ...

  3. Android美丽的对话框项目sweet-alert-dialog

    美丽的对话框 sweet-alert-dialog 项目地址: https://github.com/pedant/sweet-alert-dialog android原生的dialog太生硬了,之前 ...

  4. 【转】 Android常用实例—Alert Dialog的使用

    Android常用实例—Alert Dialog的使用 AlertDialog的使用很普遍,在应用中当你想要用户做出“是”或“否”或者其它各式各样的选择时,为了保持在同样的Activity和不改变用户 ...

  5. 【Android】Android 8种对话框(Dialog)

    1.写在前面 Android提供了丰富的Dialog函数,本文介绍最常用的8种对话框的使用方法,包括普通(包含提示消息和按钮).列表.单选.多选.等待.进度条.编辑.自定义等多种形式,将在第2部分介绍 ...

  6. 漂亮的各种弹出框 sweet alert

    Sweet Alert 是一个替代传统的 Alert 的提示效果.SweetAlert 自动居中对齐在页面中央,不管您使用的是台式电脑,手机或平板电脑看起来效果都很棒. 还带下拉 几种 动画效果 弹窗 ...

  7. android修改HOLO对话框风格

    andriod中修改对话框的风格,可以通过设置theme来实现,部分元素需要通过Java代码来修改,下面以修改对话框的标题为例说明各步骤. 1.编写一个文本样式. DIALOG的标题是一个textvi ...

  8. 9.Android之日期对话框DatePicker控件学习

    设置日期对话框在手机经常用到,今天来学习下. 首先设置好布局文件:如图 xml对应代码 <?xml version="1.0" encoding="utf-8&qu ...

  9. Android:AlertDialog对话框

    1.简单的ALertDialog: Dialog alertDialog = new AlertDialog.Builder(this) .setTitle("标题") .setM ...

随机推荐

  1. Hbase的连接池--HTablePool被Deprecated之后

      说明: 最近两天在调研HBase的连接池,有了一些收获,特此记录下来. 本文先将官方文档(http://hbase.apache.org/book.html)9.3.1.1节翻译,方便大家阅读,然 ...

  2. SOA之(3)——面向服务计算基础

    面向服务计算基础(Service-Oriented Computing Fundamentals) 面向服务的计算(Service-Oriented Computing) 面向服务的计算是一个伞状术语 ...

  3. javascript实现数据结构:线性表--线性链表(链式存储结构)

    上一节中, 线性表的顺序存储结构的特点是逻辑关系上相邻的两个元素在物理位置上也相邻,因此可以随机存取表中任一元素,它的存储位置可用一个简单,直观的公式来表示.然后,另一方面来看,这个特点也造成这种存储 ...

  4. 2014多校第六场 1005 || HDU 4925 Apple Tree

    题目链接 题意 : 给你一块n×m的矩阵,每一个格子可以施肥或者是种苹果,种一颗苹果可以得到一个苹果,但是如果你在一个格子上施了肥,那么所有与该格子相邻(指上下左右)的有苹果树的地方最后得到的苹果是两 ...

  5. VS2003 下GridControl的列显示成图片+文字的形式实现

    public RC_CustomerSolicitListUC() { // 该调用是 Windows.Forms 窗体设计器所必需的. InitializeComponent(); // TODO: ...

  6. Dev 统计GridControl界面上当前选中的一行的值

    private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChang ...

  7. Java集合框架(一)

    Java中集合类的关系图:  Collection 先来集合中的最大接口——Collection 可以通过查看JDK帮助文档,了解Collection接口中的最共性的方法.通过以下代码示例演示这些方法 ...

  8. 今天来做一个PHP电影小爬虫。

    今天来做一个PHP电影小爬虫.我们来利用simple_html_dom的采集数据实例,这是一个PHP的库,上手很容易.simple_html_dom 可以很好的帮助我们利用php解析html文档.通过 ...

  9. lintcode:Pow(x, n)

    Pow(x, n) Implement pow(x, n). 解题 直接顺序求解,时间复杂度O(N) public class Solution { /** * @param x the base n ...

  10. Map中如何把没有定义操作符<的类作为key

    Map中如何把没有定义操作符<的类作为key 其实,为了实现快速查找,map内部本身就是按序存储的(比如红黑树).在我们插入<key, value>键值对时,就会按照key的大小顺序 ...