# SweetAlertDialog **Repository Path**: ahr6e170zl/SweetAlertDialog ## Basic Information - **Project Name**: SweetAlertDialog - **Description**: https://github.com/Cazaea/SweetAlertDialog.git - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-02 - **Last Updated**: 2025-01-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Sweet Alert Dialog =================== Android版的SweetAlert,清新文艺,快意灵动的甜心弹框 [![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu) [![LICENSE](https://img.shields.io/badge/license-Anti%20996-blue.svg)](https://github.com/996icu/996.ICU/blob/master/LICENSE) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Sweet%20Alert%20Dialog-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1065) [English Version](https://github.com/cazaea/SweetAlertDialog/blob/master/README.md) 灵感来源于JS版[SweetAlert](http://tristanedwards.me/sweetalert) [Demo下载](https://github.com/pedant/sweet-alert-dialog/releases/download/v1.1/sweet-alert-sample-v1.1.apk) ## 运行示意图 ![image](https://github.com/pedant/sweet-alert-dialog/raw/master/change_type.gif) ## 安装 使用SweetAlertDialog最简单的办法就是像下面这样添加项目依赖。 **Gradle**(Module) ``` dependencies { compile 'com.github.cazaea:sweet-alert-dialog:1.0.0' } ``` **Gradle**(Project) ``` allprojects { repositories { ... maven { url 'https://jitpack.io' } ... } } ``` ## 如何开始 显示Material进度样式 SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE); pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86")); pDialog.setTitleText("Loading"); pDialog.setCancelable(false); pDialog.show(); ![image](https://github.com/pedant/sweet-alert-dialog/raw/master/play_progress.gif) 你可以通过**SweetAlertDialog.getProgressHelper()**调用materialish-progress中下面这些方法,来动态改变进度条的样式 - resetCount() - isSpinning() - spin() - stopSpinning() - getProgress() - setProgress(float progress) - setInstantProgress(float progress) - getCircleRadius() - setCircleRadius(int circleRadius) - getBarWidth() - setBarWidth(int barWidth) - getBarColor() - setBarColor(int barColor) - getRimWidth() - setRimWidth(int rimWidth) - getRimColor() - setRimColor(int rimColor) - getSpinSpeed() - setSpinSpeed(float spinSpeed) 感谢[materialish-progress](https://github.com/pnikosis/materialish-progress)项目以及[@pedant](https://github.com/pedant)的原始项目。 更多关于进度条的用法,请参见样例代码。 只显示标题: new SweetAlertDialog(this) .setTitleText("Here's a message!") .setConfirmText("确定") // 如果不设置确定按钮属性,确定按钮将不显示,便于弹出后自动消失 .show(); 显示标题和内容: new SweetAlertDialog(this) .setTitleText("Here's a message!") .setContentText("It's pretty, isn't it?") .setConfirmText("确定") .show(); 显示异常样式: new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE) .setTitleText("Oops...") .setContentText("Something went wrong!") .setConfirmText("确定") .show(); 显示警告样式: new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .show(); 显示成功完成样式: new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE) .setTitleText("Good job!") .setContentText("You clicked the button!") .setConfirmText("确定") .show(); 自定义头部图像: new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE) .setTitleText("Sweet!") .setContentText("Here's a custom image.") .setCustomImage(R.drawable.custom_img) .setConfirmText("确定") .show(); 确认事件绑定: 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(); 显示取消按钮及事件绑定: 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(); 确认后**切换**对话框样式: 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(); [更多Android原创技术分享见: cazaea.com](http://www.cazaea.com) ## 反 996 许可证 反996许可证版本1.0 版权所有(c)2017 Cazaea(http://cazaea.com) 在符合下列条件的情况下,特此免费向任何得到本授权作品的副本(包括源代码、文件和/或相关内容,以下 统称为“授权作品”)的个人和法人实体授权:被授权个人或法人实体有权以任何目的处置授权作品,包括但 不限于使用、复制,修改,衍生利用、散布,发布和再许可: 1. 个人或法人实体必须在许可作品的每个再散布或衍生副本上包含以上版权声明和本许可证,不得自行修 改。 2. 个人或法人实体必须严格遵守与个人实际所在地或个人出生地或归化地、或法人实体注册地或经营地 (以较严格者为准)的司法管辖区所有适用的与劳动和就业相关法律、法规、规则和标准。如果该司法管辖 区没有此类法律、法规、规章和标准或其法律、法规、规章和标准不可执行,则个人或法人实体必须遵守国 际劳工标准的核心公约。 3. 个人或法人不得以任何方式诱导或强迫其全职或兼职员工或其独立承包人以口头或书面形式同意直接或 间接限制、削弱或放弃其所拥有的,受相关与劳动和就业有关的法律、法规、规则和标准保护的权利或补救 措施,无论该等书面或口头协议是否被该司法管辖区的法律所承认,该等个人或法人实体也不得以任何方法 限制其雇员或独立承包人向版权持有人或监督许可证合规情况的有关当局报告或投诉上述违反许可证的行为 的权利。 该授权作品是"按原样"提供,不做任何明示或暗示的保证,包括但不限于对适销性、特定用途适用性和非侵 权性的保证。在任何情况下,无论是在合同诉讼、侵权诉讼或其他诉讼中,版权持有人均不承担因本软件或 本软件的使用或其他交易而产生、引起或与之相关的任何索赔、损害或其他责任。