Convert Figma logo to code with AI

pedant logosweet-alert-dialog

SweetAlert for Android, a beautiful and clever alert dialog

7,267
1,941
7,267
161

Top Related Projects

5,515

An Android Alerting Library

😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.

6,569

The usual Toast, but with steroids 💪

Quick Overview

Sweet Alert Dialog is an Android library that provides a customizable and beautiful alternative to the standard Android alert dialog. It offers a sleek design with animations, making it more visually appealing and user-friendly compared to the default dialog options.

Pros

  • Visually appealing and modern design
  • Customizable appearance and animations
  • Easy to implement and integrate into existing Android projects
  • Supports both Kotlin and Java

Cons

  • May not fit perfectly with all app designs or themes
  • Requires additional dependency in the project
  • Limited to Android platform only
  • Some users might prefer native Android dialogs for consistency

Code Examples

  1. Basic usage:
SweetAlertDialog(this).setTitleText("Here's a message!").show()
  1. Confirmation dialog:
SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
    .setTitleText("Are you sure?")
    .setContentText("Won't be able to recover this file!")
    .setConfirmText("Yes, delete it!")
    .setConfirmClickListener { sDialog -> 
        sDialog.dismissWithAnimation()
    }
    .show()
  1. Custom icon and background:
SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE)
    .setTitleText("Sweet!")
    .setContentText("Here's a custom image.")
    .setCustomImage(R.drawable.custom_img)
    .setBackgroundColor(Color.parseColor("#FF4081"))
    .show()

Getting Started

  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.github.f0ris.sweetalert:library:1.6.2'
}
  1. Use the dialog in your activity or fragment:
import cn.pedant.SweetAlert.SweetAlertDialog

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        SweetAlertDialog(this)
            .setTitleText("Welcome!")
            .setContentText("This is a Sweet Alert Dialog.")
            .show()
    }
}

Competitor Comparisons

5,515

An Android Alerting Library

Pros of Alerter

  • More customizable appearance with options for icon, background color, and text color
  • Supports swipe-to-dismiss functionality
  • Easier to implement multiple alerts in sequence

Cons of Alerter

  • Limited to top-of-screen alerts, less flexible positioning
  • Lacks built-in input fields or buttons for user interaction
  • May not be suitable for critical alerts that require user acknowledgment

Code Comparison

Alerter:

Alerter.create(this@YourActivity)
    .setTitle("Alert Title")
    .setText("Alert text...")
    .setDuration(3000)
    .show()

Sweet Alert Dialog:

new SweetAlertDialog(this)
    .setTitleText("Alert Title")
    .setContentText("Alert text...")
    .show();

Summary

Alerter is more suitable for non-intrusive notifications with a modern, customizable appearance. It excels in showing multiple alerts and allows easy dismissal. Sweet Alert Dialog offers more traditional alert dialogs with various styles and input options, making it better for scenarios requiring user interaction or acknowledgment. The choice between the two depends on the specific UI/UX requirements of your application.

😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.

Pros of material-dialogs

  • More comprehensive and feature-rich, offering a wider range of dialog types and customization options
  • Follows Material Design guidelines more closely, providing a modern and consistent look
  • Actively maintained with frequent updates and bug fixes

Cons of material-dialogs

  • Larger library size, which may impact app size and performance
  • Steeper learning curve due to more complex API and numerous options
  • May require more setup and configuration for basic use cases

Code Comparison

sweet-alert-dialog:

new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
    .setTitleText("Are you sure?")
    .setContentText("Won't be able to recover this file!")
    .setConfirmText("Yes, delete it!")
    .setConfirmClickListener(sDialog -> sDialog.dismissWithAnimation())
    .show();

material-dialogs:

MaterialDialog(this).show {
    title(text = "Are you sure?")
    message(text = "Won't be able to recover this file!")
    positiveButton(text = "Yes, delete it!") {
        // Handle confirmation
    }
}

Both libraries offer easy-to-use APIs for creating dialogs, but material-dialogs provides a more concise and Kotlin-friendly syntax. sweet-alert-dialog focuses on pre-designed alert styles, while material-dialogs offers more flexibility in dialog creation and customization.

6,569

The usual Toast, but with steroids 💪

Pros of Toasty

  • Lightweight and simple to implement
  • Customizable toast appearance with icons and colors
  • Supports custom fonts and durations

Cons of Toasty

  • Limited to toast-style notifications only
  • Less feature-rich compared to Sweet Alert Dialog
  • May not be suitable for complex alert scenarios

Code Comparison

Sweet Alert Dialog:

new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
    .setTitleText("Are you sure?")
    .setContentText("Won't be able to recover this file!")
    .setConfirmText("Yes, delete it!")
    .setConfirmClickListener(sDialog -> sDialog.dismissWithAnimation())
    .show();

Toasty:

Toasty.success(getApplicationContext(), "Success!", Toast.LENGTH_SHORT, true).show();
Toasty.error(getApplicationContext(), "Error!", Toast.LENGTH_SHORT, true).show();
Toasty.info(getApplicationContext(), "Info", Toast.LENGTH_SHORT, true).show();
Toasty.warning(getApplicationContext(), "Warning", Toast.LENGTH_SHORT, true).show();
Toasty.normal(getApplicationContext(), "Normal", Toast.LENGTH_SHORT).show();

Sweet Alert Dialog offers more complex and customizable alert dialogs with various styles and interactions, while Toasty focuses on enhancing Android's built-in toast notifications with additional styling options. Sweet Alert Dialog is better suited for important user interactions, while Toasty is ideal for quick, non-intrusive notifications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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.