27

I am trying to set the android Theme.Light theme for my alert dialog, but with no success so far. After reading a few tutorials I gathered that using AlertDialog.Builder we cannot set the theme directly in the constructor (atleast in API level 7).

The alternate solution that I found is using a ContextThemeWrapper, which everyone assured would solve my problem. So I coded something like this:

AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(context, R.style.popup_theme));

I described my theme in the values folder:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="back_color">#ffffffff</color>
<style name="popup_theme" parent="@android:style/Theme.Light">
    <item name="android:windowBackground">@color/back_color</item>
    <item name="android:colorBackground">@color/back_color</item>
</style>

Unfortunately I still get the default Theme.Dialog.Alert theme. Can anyone tell me why? Where am I going wrong?

EDIT: If you do not know the answer to my question, please vote up. I have a bad habit of posting questions which get stuck :(

Arnab Chakraborty
  • 7,442
  • 9
  • 46
  • 69

5 Answers5

6

change parent="android:Theme.Light" to parent="@android:style/Theme.Light"

Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
Gallal
  • 4,267
  • 6
  • 38
  • 61
4

This took me a while to figure out as well.

The issue at hand is that Theme.Light and Theme.Holo.Light and such are designed around the activity. A dialog theme needs to be based around a theme such as @android:style/Theme.Dialog which contains properties specific to dialogs.

<style name="popup_theme" parent="@android:style/Theme.Dialog">

Try overriding the Theme.Dialog using things like:

<item name="android:textAppearance">?android:attr/textAppearanceInverse</item>
tomwardiii
  • 61
  • 2
3

Try this:

<style name="popup_theme" parent="Theme.AppCompat.Light.Dialog.Alert">
Ashwin
  • 7,277
  • 1
  • 48
  • 70
1
parent="android:style/Theme.Light"
Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
Chandu
  • 1,049
  • 3
  • 11
  • 18
0

This is what I did. And it worked for me

AlertDialog.Builder builder = new AlertDialog.Builder(context,R.style.Theme_AppCompat_Light_Dialog);
Rupam Das
  • 373
  • 9
  • 19