Loading...

Android Custom Alert Dialog Example

Dialog is a window that provides information, some decision or enters additional information to the users. Most of the dialog has a title, message and some decision condition. In this article, I will show you how to display/show custom alert dialog in your android application.

Android Custom Alert Dialog ExampleCreate an Android Project


It is very easy to display dialog to your application. Let’s start by creating a new android project to show custom alert dialog to your Android application with following information:

Application name: Custom Alert Dialog Example
Company Domain: viralandroid.com
Package name: com.viralandroid.customalertdialogexample
Minimum SDK: Android 2.2 (API 8 Froyo)

Related:

Modify Activity Layout File


Add a button to your activity layout file. After adding button to your activity_main.xml file, it looks like this.
res/layout/activity_main.xml

Now, you have to create a new xml file in your layout directory to show custom dialog in your app. Your custom dialog layout will look like this.
res/layout/custom_dialog.xml


Modify Your Java Activity


Here is modified java code of MainActivity.java file.
src/MainActivity.java

Now, run your application and click Show Custom Alert Dialog button there is a dialog appeared which like below.

Android Custom Alert Dialog Example
Android Alert Dialog Box
Tutorial 7634526176985273734
Home item