8

I added the following theme to my app with a background color of white.But I get the following error and I'm not sure where I have gone wrong.

Error: Color types not allowed (at 'android:windowBackground' with value '#FF0000').

<style name="MyTheme" parent="@android:style/Theme.Light"> 
  <item name="android:windowBackground">#FF0000</item>
 </style>

And referenced the theme in mymanifest:

<activity
        android:name=".MyActivity"
        android:theme="@style/MyTheme" />

Any ideas or suggestions? Thanks

1

2 Answers 2

18

According to the Android Styles and Themes page, you have to use a separate color resource to set the color.

(Note that the color needs to supplied as a separate resource here because the android:windowBackground attribute only supports a reference to another resource; unlike android:colorBackground, it can not be given a color literal.)

For example

<item name="android:windowBackground">@color/custom_theme_color</item>
4
  • Thanks,Where would I define the custom color to reference in the windowBackground?
    – Brian Var
    Mar 20, 2013 at 13:38
  • 2
    Create a color.xml file under 'values' and then set it there. You list colors the same as strings, <color name="custom_theme_background">#ff0000</color> Mar 20, 2013 at 14:05
  • I got a new error when I declared the custom color in the windowBackground code. 'error: Error: No resource found that matches the given name (at 'android:windowBackground' with value '@color/custom_theme_color').'
    – Brian Var
    Mar 20, 2013 at 17:05
  • Ah, that'll most likely be because the names don't match. Either change the windowBackground to custom_theme_background or your color declaration to custom_theme_color Mar 20, 2013 at 20:46
2

Try:

<style name="MyTheme" parent="@android:style/Theme.Light"> 
  <item name="android:background">#FF0000</item>
</style>
2
  • Thanks that did the job,but the background color is still the same after changing color code.Is it possible I have to override the original theme?
    – Brian Var
    Mar 20, 2013 at 13:24
  • You are already overriding Theme.Light with the parent statment
    – PaperThick
    Mar 20, 2013 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.