Android custom dialog


Sometimes, we need to use our own defined dialog instead of using builin dialog provided by android. In this example, how we can build our own dialog and how we can handle different type of events.


Android custom dialog Android Custom dialog


Example


In this example, I created a custom login screen and shown it in built-in dialog of android. On click of login button, I am capturing values entered by user for user id and password and showing it in Toast.

Step 1: Create a new project in Android Studio and name it Android custom dialog.

Step 2:Open res -> drawable -> activity_main.xml and replace the code with code of activity_main.xml with the below given code.

activity_main.xml

Step 3:Open res -> drawable and create a new layout resource file and named it custom_dialog.xml. Now, open this file and replace its code with the code of my custom_dialog.xml as given below.

custom_dialog.xml

Step 4: Open MainActivity.java and replace its code with below given code.

MainActivity.java

Step 5:Clean and run your project to see the result.

Share & Like

Tutorial topics

About ApnaTutorials.com

ApnaTutorials.com is for Java, J2ee, Html5 and android developers. All tutorials are well explained and are easy to understand. We have tested every tutorials on our developement environment before posting it in public domain.