Android Android Kotlin

Android Alert Dialog Example using Kotlin3 min read

In this tutorial, we show you how to display an alert box in Android. See flowing Steps :

AlertDialog is a structure extended from Dialog that allows the user to see a popup image on the screen. We can show it as an information message to the user, or we can use the AlertDialog structure as an error message if we want.




Demo:

Android Alert Dialog Example

Step 1: Open the Android Studio IDE and Create a New Empty Activity. Name it similarly.

Step 2: Simple layout file, display a button on screen.

File : res/layout/activity_main.xml

Step 3: Step 3: Create an Intent to be shown in case of positive response.

Create a New Activity into App folder by right click. New → Activity → Empty Activity. Name as PositiveAnswer.

Step 4: Let’s write the code to create and show the AlertDialog.

File: MainActivity.kt

Android Alert Dialog
Android Alert Dialog

Leave a Comment