2011-03-29 90 views

回答

8

繼@Ryan:

在佈局自己的活動,還可以添加屬性

android:background="@android:color/white" 

設置背景顏色。您還可以引入自定義資源/res/values/colors.xml在其中你可以聲明自定義顏色。一個這樣的文件可能是這樣的:

<resources> 
<color name="fire_brick_red">#B0171F</color> 
</resources> 

然後,您可以在XML介紹這些如下:

android:background="@color/fire_brick_red" 
3

添加背景屬性到你的窗口的XML佈局。例如:

<LinearLayout android:background="@drawable/yourbackgroundimage" ... > 
36

添加android:theme="@style/Theme.AppTheme屬性到應用程序標籤在你想要使用的主題清單文件。如果您只在活動/片段佈局文件中設置背景,這將防止繪製默認的「黑色」背景。

您在style.xml文件中聲明它。

<?xml version="1.0" encoding="utf-8"?> 
<resources>  
<!-- 
    Base application theme, dependent on API level. This theme is replaced 
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
--> 
<style name="AppBaseTheme" parent="@style/Theme"> 
<!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 
--> 
</style> 
</style> 
    <!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
     <item name="android:windowBackground">@drawable/custom_background</item> 
    </style> 

</resources> 

AndroidManifest.xml文件

... 
<application 
    android:name="@string/app_name" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/Theme.AppTheme"> 
... 
哪個類的
+2

這一個應該是被接受的答案 – matto1990 2013-11-13 12:42:00

+1

這是唯一正確的答案。它設置了**應用程序**而不是**活動**背景。 – ruX 2015-05-22 15:48:38

+0

是的,它是完美的工作。但是我不明白爲什麼我們需要從'AppBaseTheme'繼承? '