2016-12-23 35 views
1

我使用下面的主題我的應用主題活動背景色:更改的使用程序兼容性主題在較舊的Android版本

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

我想改變背景顏色。爲了做到這一點,根據文檔,我可以添加以下主題定義:

<item name="windowBackground">@color/windowBackground</item> 

然而不幸的是,這只是編譯正確,如果(如在No resource found that matches the given name: attr 'windowBackground'答案建議)我把它限制在被應用於API 21或更高版本的Android版本。

我該如何在早期版本的Android上做這項工作?理想情況下,我希望爲Android版本指定一個背景顏色,直到API 16,這是我目前的最小值。

+0

'機器人:windowBackground'在加入[API 1](https://developer.android.com/reference/android /R.attr.html#windowBackground)。是什麼讓你認爲它只適用於API 21或更高版本? – ianhanniballake

+0

@ianhanniballake - 我只是使用「windowBackground」而不是「android:windowBackground」,這導致了我所鏈接到的API 21被要求的答案...... – Jules

回答

2

這是真的,你說windowBackground所以你只需要與android:windowBackground這是API 14或更高,以取代它

0

您需要添加

<item name="android:windowBackground">@color/window_background</item> 

../values- V21/styles.xml

0
// Your Problem is that You are use Theme.Appcompat then extends ActionBarActivity 

if you use AppcompatActivity then use 

<style name="MyTheme" parent="Theme.AppCompat.Light"> 
    <item name="android:windowBackground">@color/colorAccent</item> 
    </style>