Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I show my activity as a dialog in Android?

I am working on my first Android application, and am trying to style my activity. Ultimately, I would like for my activity to look the same as a dialog. I have given all my activities the Theme.Dialog style using the following code in my AndroidManifest.xml:

<application
    android:icon="@drawable/group"
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.Dialog">
</application>

This gives my activities the "floating" appearance and the borders of a dialog, but not the styled title. The title just has the same color and appearance as the general dialog background, not the "header" background and border as in a "real" dialog. Notice how in both examples the header has a nice border under it and in the second one, it has a gradient background.

Is there a way to make sure the title on my activity somehow inherits the system dialog title so as to effectively replicate the look of a dialog for my activity - in addition to the border and "float" which comes with the Theme.Dialog style?

Note that I do not want to call my activity as a dialog from another, I just want it to LOOK like a dilaog, even when it is loaded in response to an intent as per my manifest's intent-filters.

Dialog Example 1

Dialog Example 2

ADD: Is there perhaps some way I can have my activity, when it spins up in onCreate(), call some method to turn itself into an actual dialog? Keep in mind the activity still needs to be able to respond to intents from the system.

like image 899
eidylon Avatar asked Jan 05 '12 05:01

eidylon


People also ask

How do you display floating dialog in an activity?

If you use 'Theme. Dialog' for your activity, it would be shown as a floating Dialog. You can create buttons like “OK”, “CANCEL” etc for this dialog through the activity's layout.

How can I show alert dialog on top of any activity in Android app?

setMessage() is used for setting message to alert dialog. setIcon() is to set icon to alert dialog. The following code will create alert dialog with two button. setPositiveButton() is used to create a positive button in alert dialog and setNegativeButton() is used to invoke negative button to alert dialog.


1 Answers

A Dialog theme can be customised by specifying it as parent, in styles.xml

<resources>
<style name="MyDialogTheme" parent="android:Theme.Dialog">
            <item name="android:background">#ffdddddd</item>
</style>
</resources>

If you give a different color to the background of customized dialog style and the layout(add android:background="#ffffffff" under layout header in your main.xml file), it would give a system dialog like look.

Hope this helps..

Missed to mention: Refer to the customized theme in your manifest as below:

android:theme="@style/MyDialogTheme"
like image 187
Priya Kathir Avatar answered Oct 13 '22 07:10

Priya Kathir