8

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.

eidylon
  • 7,068
  • 20
  • 75
  • 118
  • which dialog you want ? first one or second one in image. – Sujit Jan 05 '12 at 05:58
  • They are both the result of calling the standard show-dialog methods. The second is the dialog as it appears themed with Samsung's TouchWiz UI, the first is as it appears themed by the skin I'm running in Cyanogenmod. Basically, I just want my activity to APPEAR AS IF it is a dialog as per whatever theme the user's device is running, the same as if I used AlertDialog.Builder. – eidylon Jan 05 '12 at 06:14

3 Answers3

4

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"
musefan
  • 47,875
  • 21
  • 135
  • 185
Priya Kathir
  • 263
  • 1
  • 6
  • Well, I am already using the `Theme.Dialog` style on my activity, but it only gives you the floating appearance, and the border around your activity. It does not style the activity's title bar. I don't necessarily want to customize the dialog look, I am rather trying to make my activity look exactly like the intrinsic dialog (however that may look as per the user's phone's theme). – eidylon Jan 05 '12 at 18:37
2

You can do as follow..

create a layout for your dialog and set in as below.

Dialog mDialog = new Dialog(MainScreen.this,android.R.style.Theme_Translucent_NoTitleBar);

mDialog .requestWindowFeature(Window.FEATURE_NO_TITLE);

mDialog .setContentView(R.layout.dialoglayout);
mDialog .show();
Sujit
  • 10,512
  • 9
  • 40
  • 45
  • I would need to add this in code in another activity though, no? My activity responds directly to launcher intents (shortcuts created on the homescreen), and I want it to look like a dialog when it is called by the system for those intents, or directly through the launcher, also. – eidylon Jan 05 '12 at 06:16
2

After deciding to look at what I wanted to do, instead of how to do it specifically, I found a different approach. I reasked my question looking for approach ideas instead of implementation ideas here. GalDude33 helped me figure out how to achieve what I wanted. His answer there was the answer to this Q.

Community
  • 1
  • 1
eidylon
  • 7,068
  • 20
  • 75
  • 118
  • Sure, but the problem with this approach is, that the result has no properties of Activity. E.g. you can't show ActionBar in your dialog. – Michal Vician Jun 02 '14 at 13:28
  • I will really admit that not bring able to use the ActionBar is the biggest disadvantage... and having to roll my own look-alike toolbar. If you can show me a way to get dialog functionality while also being able to use the ActionBar, I'd be very happy! – eidylon Jun 02 '14 at 13:32
  • I found out, that you can change activity's dimension in onCreate(...) method, however I don't know how to make black borders semitransparent, so that it looks like dialog: `WindowManager.LayoutParams params = getWindow().getAttributes(); params.height = 300; params.width = 100; getWindow().setGravity(Gravity.CENTER); getWindow().setAttributes(params); ` – Michal Vician Jun 02 '14 at 14:07