13
A
回答
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" ... >
0
就個人而言,我會嘗試做它在XML像SK9建議,但程序在運行時可以做
setBackgroundColor(int color)
或
setBackgroundResource(int resourceID)
來源: http://developer.android.com/reference/android/view/View.html
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">
...
哪個類的
是這種方法嗎? – 2014-05-03 11:55:22