9

I'm creating an AlertDialog. I'm using setView() to set a custom view. This enables the 'dark' theme on the dialog (grey background, and need white text).

Is there a way to set the dialog to use the 'light' theme? It looks nicer (white background, dark text).

Thanks

user291701
  • 38,411
  • 72
  • 187
  • 285
  • 1
    See this answer: http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog – Joe Jan 02 '11 at 00:58

1 Answers1

4

Steps I took:

  • Create a class extending Dialog.
  • In the onCreate, call setContentView(x, y) with x being your R.layout and y being R.style.popupStyle (see below).
  • In your res/values/style.xml, you need to override the default DialogWindow style. I tried just making a style that has this one as its parent, but that still didn't clear all defaults. So I checked the Android git tree and got the default style, and just copy-pasted it. This is the one

:

<style name="Theme.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowTitleStyle">@android:style/DialogWindowTitle</item>
    <item name="android:windowBackground">@android:drawable/panel_background</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>

You'll get a few errors, just solve them by copying more stuff from the official Android styles.xml and themes.xml files.

for reference: styles.xml and themes.xml.

Mitul Nakum
  • 5,514
  • 5
  • 35
  • 41
  • DialogWindowTitle don't public, should use: ?android:attr/windowTitleStyle – Yura Shinkarev Jun 16 '13 at 23:09
  • This leaves a white border around the actual dialog, so far I found no way to remove the border to be transparent so the dialog shadow is actually rendered to the real background and not on a white border – John Dec 13 '14 at 00:55