VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-create-a-custom-alertdialog-in-android/

⇱ How to Create a Custom AlertDialog in Android? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Create a Custom AlertDialog in Android?

Last Updated : 12 Jul, 2025

In some cases for the AlertDialog, there is a need to get input from the user or customize it according to our requirements. That's where custom AlertDialogs comes in handy. In this article we are going to discuss on how to customize the AlertDialogs and take user input.

Example:

👁 custom-alert-dialog-box


Steps to Implement of Custom AlertDialog

Step 1: Create an XML file custom_layout.xml

Add the below code in custom_layout.xml. This code defines the alert dialog box dimensions and adds an edit text to it.

custom_layout.xml:


Step 2: Add a Button in activity_main.xml

The button when clicked will show the AlertDialog box. 

activity_main.xml:

Layout:

👁 Layout_2


Step 3: Add custom_layout.xml file

Add custom_layout.xml in that activity in which you want to show a custom alert dialog here it is added in MainActivity.

MainActivity File:

Output:

Comment
Article Tags:

Explore