2013-03-20 76 views
7

我将以下主题添加到了我的应用程序,其背景颜色为white.But但出现以下错误,我不确定我出错的位置。将自定义主题添加到应用程序时出错

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> 

而且引用的mymanifest主题:

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

任何意见或建议?由于

+0

http://stackoverflow.com/questions/4342405/android-setselector-color-for-listview-not-working – PaperThick 2013-03-20 13:21:25

回答

16

按照Android Styles and Themes页面,你必须使用一个单独的颜色资源来设置颜色。

(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.)

例如

<item name="android:windowBackground">@color/custom_theme_color</item> 
+0

谢谢,我会在windowBackground中定义自定义颜色以引用? – 2013-03-20 13:38:23

+2

在'values'下创建一个color.xml文件,然后在那里设置它。你列出与字符串相同的颜色,''color name =“custom_theme_background”>#ff0000' – 2013-03-20 14:05:44

+0

当我在windowBackground代码中声明自定义颜色时,出现新错误。 '错误:错误:找不到与给定名称相匹配的资源(在'android:windowBackground'中,值为'@ color/custom_theme_color')。' – 2013-03-20 17:05:26

2

尝试:

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

感谢那些做了工作,但背景改变颜色代码后,颜色仍然是一样的。是否有必要重写原始主题? – 2013-03-20 13:24:34

+0

你已经覆盖Theme.Light父级陈述 – PaperThick 2013-03-20 13:36:27

相关问题