dialog is usually a small window that appears in front of the current Activity. The underlying Activity loses focus and the dialog accepts all user interaction. Dialogs are normally used for notifications that should interrupt the user and to perform short tasks that directly relate to the application in progress .
The Dialog class is the base class for creating dialogs.
Types of default dialog boxes are:
• AlertDialog
• ProgressDialog
• DatePickerDialog
• TimePickerDialog

If we wish to create a customized dialog box then we can do so in the following way:

Step 1. Create a xml layout for the dialog box and a transparent background is preferable in order to show the Activity screen underneath it.


<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:background=”@drawable/bg_dialog” >

android:background=”@drawable/mid_box” />

android:background=”@drawable/female_selector” />


Step2. Add the following code for dialog box in oncreate(),onclick() etc based on where you want the dialog box to pop. In the given example the dialog box appears as soon as the activity starts .Hence, the code is placed in oncreate() .

public void onCreate(Bundle savedInstanceState)
setContentView(R.layout.play_menu_screen);//setting layout foractivity

//put your activity related code here

Dialog(); //function call for dialog box


/*code for creating a custom dialog box */

private void Dialog()
/* creating a dialog object and specifying the activity it pops on .
PlayActivity is the activity on which dialog box appears & R.style.FullHeightDialog
Specifies that dialog box has height equivalent to screen height */

final Dialog dialog = new Dialog(PlayActivity.this,R.style.FullHeightDialog);

dialog.setContentView(R.layout.dialog_screen);//setting the dialog xml layout

/* adding action when image buttons of dialog are clicked */

new OnClickListener() {
public void onClick(View v) {

//put your code here

dialog.dismiss();//closes the dialog box

dialog.show();//pops the dialog box

This way we can create a customized dialog box .Why use the boring default dialog boxes when we can create our own.