2

I've defined an application level style :

<style name="MyApplicationStyle" parent="@android:style/Theme.Black">
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:shadowColor">#000000</item>
    <item name="android:shadowDy">2</item>
    <item name="android:shadowRadius">1.5</item>

    <item name="android:buttonStyle">@style/MyButton</item>
    <item name="android:editTextStyle">@style/MyEditText</item>
</style>

This style is applied to my application through thea activity node in the Manifest.xml:

android:theme="@style/MyApplicationStyle"

My problem is that this theme is applied everywhere, even in my AlertDialog and Dialogs. Only some features are applied in these Dialogs : the shadow for example are applied on the button and the text. I let you imagine how hard it would be to implement a new Dialog class with all the required features or to set to each Button the right style. Thus the proposed solution here : Button style in AlertDialogs is not really suitable

Is there any workaround to avoid the button style to be applied in the Dialog or to manually set a style to the Dialog (using a ContextThemeWrapper doesn't work) ?

Community
  • 1
  • 1
AsTeR
  • 7,247
  • 14
  • 60
  • 99

2 Answers2

0

You can set a specific layout for your dialog with custom style for this layout, thus overriding the applied style from your theme.

Hope this helps!

Dimitris Makris
  • 5,183
  • 2
  • 34
  • 54
  • Thank you. To my experience, when you specify a style over a layout it doesn't affect child element (only the application theme can do that). Moreover the button in the AlertDialog aren't specified through a layout, I doubt that using a theme over the layout will affect them. Maybe I'm wrong, I'll test this today. – AsTeR Oct 26 '11 at 07:13
0

Don't know if you figured this out by now but these are the internal attribute names used to style dialogs specifically (found in sdk/platforms/android-14/data/res/values/themes.xml):

<item name="alertDialogStyle">@android:style/AlertDialog</item>
<item name="dialogTheme">@android:style/Theme.Dialog</item>
<item name="dialogTitleIconsDecorLayout">@layout/dialog_title_icons</item>
<item name="dialogCustomTitleDecorLayout">@layout/dialog_custom_title</item>
<item name="dialogTitleDecorLayout">@layout/dialog_title</item>
<item name="alertDialogTheme">@android:style/Theme.Dialog.Alert</item>
<item name="alertDialogCenterButtons">true</item>
<item name="alertDialogIcon">@android:drawable/ic_dialog_alert</item>
<item name="toastFrameBackground">@android:drawable/toast_frame</item>

Adding android: infront of these (most of the time) allows you to override them. I haven't yet found any documentation for this so if you come across some let me know! I've done some pretty nifty stuff by trial and error by overriding some of this stuff.

You can see what android is doing now by looking here: sdk/platforms/android-14/data/res/values/styles.xml

Graeme
  • 25,714
  • 24
  • 124
  • 186
  • In what you give, only android:alertDialogStyle doesn't create compile error. Setting shadow for this one doesn't change anything in my problem. After looking in sdk/platforms/android-14/data/res/values/styles.xml I think that the problem is that button style is set in a general way (not considering Dialog as a different component)... that's strange cause the color isn't applied on dialog buttons : only the shadow. Thanks for your help – AsTeR Dec 01 '11 at 22:59
  • If styling is applied differently there has got to be a difference in the heirachy somewhere. Take a look at `parent="@android:style/Theme.Black"` and it's parents (unless specified, `Theme.Black` 's parent is `Theme`. – Graeme Dec 02 '11 at 09:20
  • I've tried to inheritate the dialog style from this one, doesn't change a thing. – AsTeR Dec 02 '11 at 11:56
  • Oh, no, I meant, have a look at the `` tags that are inside `Theme.Black` - You can find them in Themes.xml and styles.xml above (for your target ADK). If not in `Theme.Black` then try `Theme`. The parents are heirarcicaly based on the `. (dot)` notation. `Theme.black.notitlebar` is Everything in `Theme` overwritten by everything in `Black` overwritten by everything in `notitlebar`. – Graeme Dec 05 '11 at 10:09