Click here to Skip to main content
12,697,311 members (28,356 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

22.3K views
7 bookmarked
Posted

Style Any Activity as an Alert Dialog in Android

, 19 Jul 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Simple trick that I find very useful

Introduction

This simple trick shows how to change the theme of any activity in Android to take on a dialog form.

Using the Code

Normal activities in Android take up the full-screen form. For example, here is a screenshot from my app "Periodic Table Pro":

and here is the corresponding activity declaration in the AndroidManifest.xml file:

<activity
android:name="com.aman.periodictablepro.HelperActivity"
android:label="@string/helper_activity_name" > 
</activity>

However, there is small trick that can be done to make any activity take on a Dialog form. For example, if we change the activity declaration in the AndroidManifest.xml file to this:

<activity
android:name="com.aman.periodictablepro.HelperActivity"
android:theme="@android:style/Theme.Holo.Dialog"
android:label="@string/helper_activity_name" >
</activity> 

What this android:theme="@android:style/Theme.Holo.Dialog" does is change the theme of an activity. It's still a complete activity, but it has taken on a dialog form.

Here is the screenshot afterwards:

Let me know what you guys think in the comments. Happy coding !!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Amanpreet Mukker
Software Developer
United States United States
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
Answerthanks sir this code helped me, please post like this tricky thing regards vanitha Pin
Member 110943348-Nov-14 15:48
memberMember 110943348-Nov-14 15:48 
QuestionApp getting Force Closed Pin
curious_S@n$k@r14-May-14 7:02
membercurious_S@n$k@r14-May-14 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 19 Jul 2013
Article Copyright 2013 by Amanpreet Mukker
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid