2016-12-23 33 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>