2013-03-20 73 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

相關問題