1 Star 1 Fork 1

shaoyiqing / sweet-alert-dialog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Sweet Alert Dialog

Android版的SweetAlert,清新文艺,快意灵动的甜心弹框

Android Arsenal

English Version

灵感来源于JS版SweetAlert

Demo下载

运行示意图

image

安装

使用SweetAlertDialog最简单的办法就是像下面这样添加项目依赖。

Maven

<dependency>
  <groupId>cn.pedant.sweetalert</groupId>
  <artifactId>library</artifactId>
  <version>1.3</version>
  <type>aar</type>
</dependency>

Gradle

repositories {
    mavenCentral()
}

dependencies {
    compile 'cn.pedant.sweetalert:library:1.3'
}

如何开始

显示Material进度样式

SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE);
pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86"));
pDialog.setTitleText("Loading");
pDialog.setCancelable(false);
pDialog.show();

image

你可以通过**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项目以及@croccio的参与。

更多关于进度条的用法,请参见样例代码。

只显示标题:

new SweetAlertDialog(this)
    .setTitleText("Here's a message!")
    .show();

显示标题和内容:

new SweetAlertDialog(this)
    .setTitleText("Here's a message!")
    .setContentText("It's pretty, isn't it?")
    .show();

显示异常样式:

new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE)
    .setTitleText("Oops...")
    .setContentText("Something went wrong!")
    .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!")
    .show();

自定义头部图像:

new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE)
    .setTitleText("Sweet!")
    .setContentText("Here's a custom image.")
    .setCustomImage(R.drawable.custom_img)
    .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原创技术分享见: pedant.cn

License

The MIT License (MIT)

Copyright (c) 2014 Pedant(http://pedant.cn)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sweet Alert Dialog =================== SweetAlert for Android, a beautiful and clever alert dialog [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Sweet%20Alert%20Dialog-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1065) [中文版](https://github.com/pedant/sweet-alert-dialog/blob/master/README.zh.md) Inspired by JavaScript [SweetAlert](http://tristanedwards.me/sweetalert) [Demo Download](https://github.com/pedant/sweet-alert-dialog/releases/download/v1.1/sweet-alert-sample-v1.1.apk) ## ScreenShot ![image](https://github.com/pedant/sweet-alert-dialog/raw/master/change_type.gif) ## Setup The simplest way to use SweetAlertDialog is to add the library as aar dependency to your build. **Maven** <dependency> <groupId>cn.pedant.sweetalert</groupId> <artifactId>library</artifactId> <version>1.3</version> <type>aar</type> </dependency> **Gradle** repositories { mavenCentral() } dependencies { compile 'cn.pedant.sweetalert:library:1.3' } ## Usage show material progress 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) You can customize progress bar dynamically with materialish-progress methods via **SweetAlertDialog.getProgressHelper()**: - 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) thanks to the project [materialish-progress](https://github.com/pnikosis/materialish-progress) and [@croccio](https://github.com/croccio) participation. more usages about progress, please see the sample. A basic message: new SweetAlertDialog(this) .setTitleText("Here's a message!") .show(); A title with a text under: new SweetAlertDialog(this) .setTitleText("Here's a message!") .setContentText("It's pretty, isn't it?") .show(); A error message: new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE) .setTitleText("Oops...") .setContentText("Something went wrong!") .show(); A warning message: new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .show(); A success message: new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE) .setTitleText("Good job!") .setContentText("You clicked the button!") .show(); A message with a custom icon: new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE) .setTitleText("Sweet!") .setContentText("Here's a custom image.") .setCustomImage(R.drawable.custom_img) .show(); Bind the listener to confirm button: 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(); Show the cancel button and bind listener to it: 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(); **Change** the dialog style upon confirming: 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(); [more android tech shares: pedant.cn](http://www.pedant.cn) ## License The MIT License (MIT) Copyright (c) 2014 Pedant(http://pedant.cn) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

SweetAlert for Android, a beautiful and clever alert dialog http://www.pedant.cn 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shaoyiqing/sweet-alert-dialog.git
git@gitee.com:shaoyiqing/sweet-alert-dialog.git
shaoyiqing
sweet-alert-dialog
sweet-alert-dialog
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891