Android Custom Dialog Example – Making Custom AlertDialog

In this post we will see an Android Custom Dialog Example. I hope you know about creating Dialogs in Android, and then you might be thinking that what if I can customized the dialog completely as per my need. Then the answer is “YES” you can customized it as you want, you can put whatever design or component you need in your Alert Dialog.

Enough talking right? Now let’s start our Android Custom Dialog Example.

Android Custom Dialog Example

  • Again the first thing is creating a new Android Studio project. You can implement the same in your existing project too.
  • I have created a project named Android Custom Dialog.
  • First come inside colors.xml and change the default colors to the following.

  • Now below you can see the design of the Custom Dialog that I am going to create.
Android Custom Dialog Example
Android Custom Dialog Example
  • For the above design we have defined the colors, now we need the background of the OK button and the icon for the header.
  • For the button background just create a new drawable resource file named button_background.xml and put the following code.

  • For the icon that is displaying in the header, create one more drawable file. I created ic_success.xml and put the following code inside.

  • You can also use any other icon if you want.
  • Now for our Custom Alert Dialog create a layout. I have created my_dialog.xml. Inside this file we will design our Android Custom Dialog.

  • The above layout code will generate the following design.
Android Custom Dialog Example
Android Custom Dialog Example
  • Now we need to display the above Custom Dialog Design as an Alert Dialog when a button is clicked.
  • For this come inside activity_main.xml and create a button inside the activity.

  • So your activity_main.xml will look as below.
Android Custom Dialog
Android Custom Dialog
  • Now the last task is to display our Custom Dialog when the button is clicked.
  • For displaying the dialog come inside MainActivity.java and write the following code.

  • Now run the application and you will see your custom alert dialog on clicking the button.
Android Custom Dialog Example
Android Custom Dialog Example

Bingo! It is working absolutely fine. Let me know in comments if you are having any question regarding this Android Custom Dialog Example.

And if you found this post helpful, then please help me by sharing this post with your friends learning Android Application Development. Thank You 🙂

5 thoughts on “Android Custom Dialog Example – Making Custom AlertDialog”

Leave a Comment