Android Tutorial
Software Setup and Configuration
Android Studio
File Structure
Components
Core Topics
Layout
View
Button
Intent and Intent Filters
Toast
RecyclerView
Fragments
Adapters
Other UI Component
Image Loading Libraries
Date and Time
Material Design
Bars
Working with Google Maps
Chart
Animation
Database
Advance Android
Jetpack
Architecture
App Publish
App Monetization
SweetAlert Dialog is a library for Android that provides beautiful and richly styled alert dialogs. Using SweetAlert Dialog to create alert dialogs is quite straightforward.
Here's how you can create an AlertDialog
box using the SweetAlert Dialog library:
First, add the library to your build.gradle
(Module: app):
implementation 'cn.pedant.sweetalert:library:1.3'
Ensure to check for the latest version on the library's GitHub page or Maven repository.
Here's how you can use the library to create various types of alert dialogs:
SweetAlertDialog(this) .setTitleText("Here's a message!") .show()
SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE) .setTitleText("Oops...") .setContentText("Something went wrong!") .show()
SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("You won't be able to recover this file!") .setConfirmText("Yes, delete it!") .setConfirmClickListener { sDialog -> sDialog .setTitleText("Deleted!") .setContentText("Your file has been deleted!") .setConfirmText("OK") .setConfirmClickListener(null) .changeAlertType(SweetAlertDialog.SUCCESS_TYPE) } .show()
SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE) .setTitleText("Loading") .show()
The SweetAlert Dialog provides a wide range of customization options:
SUCCESS_TYPE
, ERROR_TYPE
, NORMAL_TYPE
, etc.).If you want to close/dismiss the dialog, you can simply call:
sweetAlertDialog.dismiss()
That's it! The SweetAlert Dialog library makes it easy to create and customize alert dialogs in Android with a fresh and polished look.
Create AlertDialog with SweetAlert in Android Studio:
new SweetAlertDialog(context, SweetAlertDialog.NORMAL_TYPE) .setTitleText("Title") .setContentText("Content text") .show();
Customize SweetAlert dialog in Android:
new SweetAlertDialog(context, SweetAlertDialog.SUCCESS_TYPE) .setTitleText("Custom Title") .setContentText("Custom Content") .setConfirmText("OK") .showCancelButton(true) .setCancelText("Cancel") .show();
SweetAlert dialog example in Android:
new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("You won't be able to recover this file!") .setConfirmText("Yes, delete it!") .show();
Custom themes for SweetAlert AlertDialog in Android:
new SweetAlertDialog(context, SweetAlertDialog.CUSTOM_IMAGE_TYPE) .setTitleText("Custom Theme") .setContentText("This dialog has a custom theme.") .setCustomImage(R.drawable.custom_image) .show();
Animate AlertDialog with SweetAlert in Android:
new SweetAlertDialog(context, SweetAlertDialog.PROGRESS_TYPE) .setTitleText("Loading") .setContentText("Please wait...") .show();