Android Alert Dialog Example

Android Alert Dialog Example | Alert Dialog in Android Studio Example

Android Alert Dialog is a Dialog box that prompts a user to take an action. It does not fill the screen but appears in the center as a message before a user can proceed. In this example we will learn how to make Android Alert Dialog Example.


Normally Alert dialog has two buttons POSITIVE and NEGATIVE. We can also use a neutral button in Alert Dialog. In Alert Dialog in the picture below you can see an Alert Dialog with three buttons. POSITIVE, NEGATIVE and NEUTRAL buttons.


Android Alert Dialog Example
Android Alert Dialog Example


Alert Dialog is used when a user wants to decide an action between two options. Like we see in almost all android apps. For example in an android phone if a user wants to uninstall an application the android system prompts a message. It asks the user if he/she “wants to remove the selected application or not”. So in easy words such a message box that prompts a user to take an action is called an ALERT DIALOG BOX.

You can use some other methods to customize the appearance of your Alert Dialog.

1- setIcon(Drawable icon)

2- setIcon(int resId)

3- setTitle(CharSequence title)

4- setMessage(CharSequence message)

5- setView(View view)


Lets learn How to Design a simple Alert Dialog with Android Alert Dialog Example:

1- So create a new Android Studio Project and name it “Alert Dialog” . Or you can name it anything you want. After the project builds go to “activity_main.xml” file.

2- But, here in “activity_main.xml” file first change the Constraint Layout into Relative Layout.

3- After Changing the Layout into Relative Layout add the “activity_main.xml” code into your “activity_main.xml” file.

4- After that, come to your main file “” . Add “” code into your “” file.

5- But, you can change the message in Toast and set it according to your choice.

6- After Using the following blocks of code you will see an Alert Dialog as output with two buttons.








So, here we complete our Android custom dialog example. I hope this Android AlertDialog Example will help you understand more about Android Alert Dialog. Then, after all this code finally the output will be like this.


Android Alert Dialog Example
Android Alert Dialog With Example




     People Also Read





8 thoughts on “Android Alert Dialog Example | Alert Dialog in Android Studio Example”

  1. Pingback: Android Progress Bar Horizantal Progress Bar In ANDROID

  2. Pingback: Android Horizontal Scroll View is a Layout container for a view hierarchy

  3. Pingback: Android Indeterminate Progress Bar: How to create Progress Bar

  4. Pingback: Android Horizontal ScrollView Example: Horizontal Scroll View In Android

  5. Pingback: Android ListView Example in Java: ListView in Android Studio

  6. Pingback: AlertDialog Android Kotlin | AlertDialog in Kotlin with Example

  7. Pingback: RecyclerView With Data Binding in Android Kotlin: Example With Kotlin

  8. Pingback: How To Display Text in TextView Using Kotlin: Android Studio Kotlin

Leave a Comment

Your email address will not be published. Required fields are marked *