In this article, we will learn about how to add Custom Alert Dialog in an app using SweetAlert Dialog Library. It is a pop-up box which appears in response to any action of the user.AlertBox is very useful when it comes to validation, it can be used to display confirmation messages. Suppose if the user presses the Back Button without saving the changes then for warning it can be used. When the transaction is done in payment apps a short Dialog Box can be shown to the user describing the status of the transaction.
- It provides us a very good user interface which makes the user experience very good.
- It makes the work very much easier so it is used over Custom Dialog which needs whole layout to be created.
- It provides many different types of layouts for the dialog box.
Step 1: Add the support Library in build.gradle file and add dependency in the dependencies section. This library has inbuilt alert dialog which can be directly used.
Step 2: Now add the following code in activity_main.xml file. This code adds five buttons in the activity. Each button is used to call differnt style of Alert Dialog Box.
Step 3: Add the following code in MainActivity.java file. Now on clicking any button the showDialog() function is started and corresponding Alert Dialog Box is displayed. onClickListner can also be added to the button instead of showDialog function.
Reference Link: https://github.com/F0RIS/sweet-alert-dialog