Creating the Custom Activity dialog
Create an activity as you normally would.
Create the activity’s layout file. This is what mine looks like:
This is a normal activity
It’s all in the Theme: Edit the manifest
Open up the AndroidManifest.xml file.
Edit your activity element to include the theme attribute:
Set the theme for the activity to make it look like a dialog
The theme floats the activity window and puts a frame around its contents.
Which theme you choose depends on your target devices.
- Theme.Dialog – default for API 10 and lower
- Theme.Holo.Dialog – default for API 11 and newer
Using Theme.Dialog turns the activity into a dialog
Showing the Custom Activity dialog
Just start the activity to show the dialog.
Here’s how I did it:
Create an Intent using this constructor, Intent(context, the activity that we want to start).
Call startActivity(), passing the intent. This will start the activity and display the “dialog”.
You can then capture the user’s input as you would with any activity.
It’s really that simple!
I hope you found this tutorial helpful.
Here are the links to all the tutorials in this series on Android Dialogs;
- Coding Android dialogs the easy way
- Making a list: Coding List Dialogs
- Making a list: Coding Multiple-choice List Dialogs
- Coding Android Custom Dialogs the easy way
- Coding Android Activity dialogs the easy way
This project was created using Android Studio. You can download the project files here
Are you using Eclipse or another IDE? Here's how you can use this project's Android Studio files.