views:

367

answers:

2

Does anyone know how to override the default style for AlertDialog buttons? I've looked through the Android source for themes and styles and experimented with different things but I haven't been able to find a way that works.

What I've got below works for changing the backgrounds, but doesn't do anything with the buttons. myTheme is applied to the whole <application> via the manifest. (Some other items were deleted for clarity, but they only relate to the title bar.)

<style name="myTheme" parent="android:Theme">
    <item name="android:buttonStyle">@style/customButtonStyle</item>
    <item name="android:alertDialogStyle">@style/dialogAlertTheme</item>
</style>

<style name="dialogAlertTheme" parent="@android:style/Theme.Dialog.Alert">
    <item name="android:fullDark">@drawable/dialog_loading_background</item>
    <item name="android:topDark">@drawable/dialog_alert_top</item>
    <item name="android:centerDark">@drawable/dialog_alert_center</item>
    <item name="android:bottomDark">@drawable/dialog_alert_bottom</item>
    <!-- this last line makes no difference to the buttons -->
    <item name="android:buttonStyle">@style/customButtonStyle</item> 
</style>

Any ideas?

+1  A: 

I guess you have to implement your own Dialog class.

MrSnowflake
Hmm. That'd be annoying; changing Dialog buttons shouldn't be that an unusual of a thing to do, considering that it's easy to apply a button style to the 'normal' Activity buttons.
Steve H
In normal activities you define the layout of the content view with an xml. Dialog does this for you, so you don't have access to the layout xml. Implementing your own dialog (possibly with only a setContentView() call) allows you to use a different xml and thus different styles for buttons.
MrSnowflake
A: 

The AlertDialog.Builder hardcodes the theme :-(

Allan