Activity as a Dialog – Android

It’d be cool to have an Activity to be shown like a Dialog, with the previous activity still in the background.

It turns out that this can easily be done, making use of the android:theme attribute in your activity tag in the AndroidManifest.xml file.

<activity
 android:name=".YourActivityName"
 android:theme="@style/CustomDialog" >
 </activity>

where CustomDialog is a style that we declare in styles.xml (which should go into the res/values folder). Put the following inside the styles.xml.

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="CustomDialog" parent="@android:style/Theme.Dialog">
 <item name="android:windowBackground">@color/transparent</item>
 <item name="android:windowIsFloating">true</item>
 <item name="android:windowNoTitle">true</item>
 </style>

</resources>

Start your activity, as you normally would, using startActivity(Intent intent).

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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