SweetAlert for Android, a beautiful and clever alert dialog

Overview

Sweet Alert Dialog

SweetAlert for Android, a beautiful and clever alert dialog

Android Arsenal

中文版

Inspired by JavaScript SweetAlert

Demo Download

ScreenShot

image

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

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 and @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

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.
Comments
  • Possible window leak

    Possible window leak

    Since the dismiss() method is doing some async work there(modal out animation, https://github.com/pedant/sweet-alert-dialog/blob/master/library/src/main/java/cn/pedant/SweetAlert/SweetAlertDialog.java#L310 ) , Dialog.dismiss() may not be invoked before the container activity actually stopped/finished. Would be great if we can provide some sync dismiss() method there.

    opened by UglyTroLL 8
  • ProGuard Issue

    ProGuard Issue

    java.lang.RuntimeException: Unknown animation name: cn.pedant.SweetAlert.Rotate3dAnimation error:cn.pedant.SweetAlert.Rotate3dAnimation at cn.pedant.SweetAlert.a.a(Unknown Source) at cn.pedant.SweetAlert.a.a(Unknown Source) at cn.pedant.SweetAlert.a.a(Unknown Source) at cn.pedant.SweetAlert.a.a(Unknown Source) at cn.pedant.SweetAlert.j.(Unknown Source) at cn.pedant.SweetAlert.j.(Unknown Source) at my.app.a.a(Unknown Source) at my.app.a.f.onClick(Unknown Source) at android.view.View.performClick(View.java:4443) at android.view.View$PerformClick.run(View.java:18433) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5021) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643) at dalvik.system.NativeStart.main(Native Method)

    opened by mrfanatic 7
  • AS failed to build after add v1.3 into gradle depdencies

    AS failed to build after add v1.3 into gradle depdencies

    After I add compile 'cn.pedant.sweetalert:library:1.3' into my Android Studio Gradle build file, I got an error message in build `Error:Gradle: Execution failed for task ':XXX:processOfficialDebugResources'.

    com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\ProgramPortable\android-sdk\build-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1` I tried many solutions like re-install the build tool, but it does not work. This may be a environment issue, however, it works well after I change v1.3 to v1.2.

    ps.add tools:replace="android:icon" into androidmanifest.xml is useless.

    Thanks

    opened by zhangchaoxu 6
  • Dialog components going out of dialog

    Dialog components going out of dialog

    Hi. I am implementing basic usage of the dialog. I call the dialog and the dialog structure is always improper (in all Success, error, warning etc dialogs). I have attached a screenshot. Do you happen to know the cause or the solution? screenshot_2014-11-29-15-44-47

    opened by vipulyaara 6
  • I can't import your great job into my project

    I can't import your great job into my project

    I use Eclipse to develop android and want to use your library, first I import it into Eclipse, second click right button and chose property then let it be a library.

    finally, use the same method to add it as a dependency of my project, but it show me the "The constructor SweetAlertDialog(new Handler(){}, int) is undefined", I think my step is correct.

    Is it can't use this way to import?

    opened by npes87184 5
  • Unknown animation name: cn.pedant.SweetAlert.Rotate3dAnimation error:null error with gradle android plugin version 3.0

    Unknown animation name: cn.pedant.SweetAlert.Rotate3dAnimation error:null error with gradle android plugin version 3.0

    When I update gradle android plugin version from 2.3 to 3.0 I receive the following error:

    E/AndroidRuntime: FATAL EXCEPTION: main Process: com.sayaraah.app, PID: 8821 java.lang.RuntimeException: Unknown animation name: cn.pedant.SweetAlert.Rotate3dAnimation error:null at cn.pedant.SweetAlert.OptAnimationLoader.createAnimationFromXml(OptAnimationLoader.java:77) at cn.pedant.SweetAlert.OptAnimationLoader.createAnimationFromXml(OptAnimationLoader.java:64) at cn.pedant.SweetAlert.OptAnimationLoader.createAnimationFromXml(OptAnimationLoader.java:41) at cn.pedant.SweetAlert.OptAnimationLoader.loadAnimation(OptAnimationLoader.java:22) at cn.pedant.SweetAlert.SweetAlertDialog.(SweetAlertDialog.java:80) at com.sayaraah.app.ui.activity.HomeActivity.onNavigationItemSelected(HomeActivity.java:153) at android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:156) at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822) at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:156) at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:969) at android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:342) at android.view.View.performClick(View.java:5637) at android.view.View$PerformClick.run(View.java:22433) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6186) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

    opened by ogasimli 3
  • show status bar when sweet alert dialog show

    show status bar when sweet alert dialog show

    In my app, there's no status bar (see my way below to hide status bar). However, every time I show alert dialog, the status bar is coming annoying again.

    View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.hide(); }

    opened by skywalkerlw 3
  • java.lang.NoSuchFieldError: cn.pedant.SweetAlert.R$id.title_text

    java.lang.NoSuchFieldError: cn.pedant.SweetAlert.R$id.title_text

    I am using sweet dialog to show dialog on in my app here is my code, SweetAlertDialog pDialog = new SweetAlertDialog(mContext, SweetAlertDialog.PROGRESS_TYPE); pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86")); pDialog.setTitleText("Loading"); pDialog.setCancelable(false); pDialog.show();

    Got Runtime Error: E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NoSuchFieldError: cn.pedant.SweetAlert.R$id.title_text at cn.pedant.SweetAlert.SweetAlertDialog.onCreate(SweetAlertDialog.java:143) at android.app.Dialog.dispatchOnCreate(Dialog.java:351) at android.app.Dialog.show(Dialog.java:256) at com.cloudvisionsystems.webapp.ShowWebView$1.onLoadResource(ShowWebView.java:98) at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:529) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4895) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761) at dalvik.system.NativeStart.main(Native Method)

    opened by Bharatchavan20 3
  • Unable to make setCancelable = false

    Unable to make setCancelable = false

    Dialog cancels every time when clicked outside of the dialog. It should be optional. Currently, it is only available in the progress dialog part.

    new SweetAlertDialog(context, SweetAlertDialog.SUCCESS_TYPE) .setTitleText("Success") .setContentText("YAY!!! Your trip is complete!") .setCancelable(false) .setConfirmClickListener(sDialog -> { sDialog.dismissWithAnimation(); }) .show();

    on the above code, .setCancelable(false) is not working and after adding that link the bottom section is showing red errors.

    opened by nirjanmunshi 2
  • Chnage Confirm Button background color

    Chnage Confirm Button background color

    How to change the confirm button background color of sweet alert in android?

    SweetAlertDialog confirmation_dialog; confirmation_dialog = new SweetAlertDialog(HeartBeatIndexModule.this, SweetAlertDialog.NORMAL_TYPE); confirmation_dialog.setTitleText("Do you want to Start?"); confirmation_dialog.setContentText("Are you Sure"); confirmation_dialog.show();

    opened by jainshravan123 2
  • Binary XML file line #112: Error inflating class com.pnikosis.materialishprogress.ProgressWheel

    Binary XML file line #112: Error inflating class com.pnikosis.materialishprogress.ProgressWheel

    I randomly get this kind of error. But It gone when I clean and rebuild the projects. Is it normal ?

    ERR: stack=android.view.InflateException: Binary XML file line #112: Binary XML file line #112: Error inflating class com.pnikosis.materialishprogress.ProgressWheel at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method) at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:334) at android.view.LayoutInflater.inflate() at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) at android.app.Dialog.setContentView(Dialog.java:512) at cn.pedant.SweetAlert.SweetAlertDialog.onCreate(SweetAlertDialog.java:140)

    opened by felangga 2
  • Next line

    Next line

    I am can't to use "\n" or "\r" or "\n\r" in setContentText(tariffDescription). description = String.format("%s%n%s", "Name: " + name + "\r\n", "Cost: " + amount);

    I have tried a lot of variations, but all of them are not working.

    opened by Aecttann 3
Releases(v1.1)
Alert Dialog - You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment.

We show a warning message (Alert Dialog) to the user in many parts of our applications. You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment. Thanks to this extension, you can create a Dialog and call it in the Activity or Fragment you want and customize the component you want.

Gökmen Bayram 0 Jan 9, 2022
AlertDialog for Android, a beautiful and material alert dialog to use in your android app.

AlertDialog for Android, a beautiful and material alert dialog to use in your android app. Older verion of this library has been removed

Akshay Masram 124 Dec 28, 2022
Make your native android Dialog Fancy and Gify. A library that takes the standard Android Dialog to the next level with a variety of styling options and Gif's. Style your dialog from code.

FancyGifDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ...

Shashank Singhal 522 Jan 2, 2023
AlertDialog - Explain about Alert Dialog in Android

AndroidTemplate I got a problem to create Android project with Java 11 and anoth

Monthira Chayabanjonglerd 1 Feb 13, 2022
Android has a built in microphone through which you can capture audio and store it , or play it in your phone. There are many ways to do that but with this dialog you can do all thats with only one dialog.

# Media Recorder Dialog ![](https://img.shields.io/badge/Platform-Android-brightgreen.svg) ![](https://img.shields.io/badge/Android-CustomView-blue.sv

Abdullah Alhazmy 73 Nov 29, 2022
An beautiful and easy to use dialog library for Android

An beautiful and easy to use dialog library for Android

ShouHeng 22 Nov 8, 2022
[Deprecated] This project can make it easy to theme and custom Android's dialog. Also provides Holo and Material themes for old devices.

Deprecated Please use android.support.v7.app.AlertDialog of support-v7. AlertDialogPro Why AlertDialogPro? Theming Android's AlertDialog is not an eas

Feng Dai 468 Nov 10, 2022
Advanced dialog solution for android

DialogPlus Simple and advanced dialog solution. Uses normal view as dialog Provides expandable option Multiple positioning Built-in options for easy i

Orhan Obut 5k Dec 29, 2022
An Android Dialog Lib simplify customization.

FlycoDialog-Master 中文版 An Android Dialog Lib simplify customization. Supprot 2.2+. Features [Built-in Dialog, convenient to use](#Built-in Dialog) [Ab

Flyco 2.3k Dec 8, 2022
Android library to show "Rate this app" dialog

Android-RateThisApp Android-RateThisApp is an library to show "Rate this app" dialog. The library monitors the following status How many times is the

Keisuke Kobayashi 553 Nov 23, 2022
A simple file/ directory picker dialog for android

FileListerDialog FileListerDialog helps you to list and pick file/directory. Library is built for Android Getting Started Installing To use this libra

Yogesh S 446 Jan 7, 2023
a quick custom android dialog project

QustomDialog Qustom helps you make quick custom dialogs for Android. All this is, for the time being, is a way to make it easy to achieve the Holo loo

Daniel Smith 183 Nov 20, 2022
Android library that allows applications to add dialog-based slider widgets to their settings

Android Slider Preference Library Overview Slider represents a float between 0.0 and 1.0 Access with SliderPreference.getValue() or SharedPreferences.

Jay Petacat 135 Nov 29, 2022
An Android library for displaying a dialog where it presents new features in the app.

WhatIsNewDialog What is new dialog for Android is used for presenting new features in the the app. It can be used in the activity starts, from menu or

NonZeroApps 22 Aug 23, 2022
Android library to show "Rate this app" dialog

Android-RateThisApp Android-RateThisApp is an library to show "Rate this app" dialog. The library monitors the following status How many times is the

Keisuke Kobayashi 553 Nov 23, 2022
A simple library to show custom dialog with animation in android

SmartDialog A simple library to show custom dialog in android Step 1. Add the JitPack repository to your build file allprojects { repositories {

claudysoft 9 Aug 18, 2022
CuteDialog- Android Custom Material Dialog Library

A Custom Material Design Dialog Library for Android Purpose CuteDialog is a Highly Customizable Material Design Android Library. CuteDialog allows dev

CuteLibs - Smart & Beautiful Android Libraries 7 Dec 7, 2022
An easy to use, yet very customizable search dialog

search-dialog An awesome and customizable search dialog with built-in search options. Usage First add jitpack to your projects build.gradle file allpr

Mad Mirrajabi 518 Dec 15, 2022
Common dialog fragments

Common dialog fragments

null 6 Aug 29, 2022