Change Dialog Theme for every Dialog

2019-02-16 15:27发布

问题:

Im using Theme.Holo.Light.DarkActionBar but I dont really like the Light Dialogs/AlertDialogs.

I want to change every Dialog to the dark Holo Dialog.

<style name="CustomDialogTheme" parent="@android:style/Theme.Holo.Dialog">
    <item name="@android:background">#9933CC</item>
    <item name="@android:textColor">#02FA07</item>
</style>

<style name="Holo.Light.DarkActionBar" parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:dialogTheme">@style/CustomDialogTheme</item>
    <item name="android:alertDialogStyle">@style/CustomDialogTheme</item>
</style>

Thats what I tried but it has no effect on any Dialogs.

回答1:

Ok nvm Im stupid its android:alertDialogTheme instead of android:alertDialogStyle. But this messes up the Preference Dialogs, so I just keep using the Light Dialogs.



回答2:

In AndroidManifest.xml under the application tag, add this line :

android:theme="Holo.Light.DarkActionBar"

The issue is that the styles you're changing android:background and android:textColor are not dialog attributes.

You can see a full list here under Theme.Holo.Dialog on line 1617.

The ones you have to change are probably android:windowBackground and textAppearance