Android: Custom A Simple Dialog



Above is the result of this demo (A dialog with your own custom layout).

Step 1: Create new layout resource for the dialog we are going to custom next. As you see in the pic above, we have one TextView & one ImageView, we can use any image for this example, copy and paste to “Drawable” folder in your resource.

Step 2: In our example, when we click a button, then a new dialog appear. So first we add a new Button for main layout and set Click event for this button. In the “onClick” method, see below:

<pre>Dialog d = new Dialog(MainActivity.this);

Window w = d.getWindow();

d.setTitle("Hello"); // set the title for dialog

// textview & imageview in your custom layout.
TextView tv = (TextView) d.findViewById(;
ImageView img = (ImageView) d.findViewById(;

tv.setText("Hello world");

Run and see the result :)



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s