2014-05-20 17 views
0

我有应用程序,它是在android:Theme.Light中创建的。我想将其更改为Theme.AppCompat.Light.DarkActionBar,但我得到更改android:Theme.Light到Theme.AppCompat.Light.DarkActionBar

没有资源发现,给定名称 “theme.appcompat.light.darkactionbar”

我有匹配android- support-v4.jar,当我尝试添加appcompat_v7我在代码中得到错误,在哪里是这样的R .....我可以添加DarkActionBar到这个项目没有代码的问题?没有修改代码?

我:

<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="android:Theme.Light"> 
     <!-- 
      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> 

    <!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    </style> 

</resources> 

我想:

<resources> 

    <!-- 
     Base application theme for API 14+. This theme completely replaces 
     AppBaseTheme from BOTH res/values/styles.xml and 
     res/values-v11/styles.xml on API 14+ devices. 
    --> 
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- API 14 theme customizations can go here. --> 
    </style> 

</resources> 

回答

2

确保您的应用程序与支持资源库(see documentation here)正确链接。

而且不要忘记@style/

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> 

这将防止no resource发生错误。 您可能也有兴趣this tutorial

+0

我得到:找不到与给定名称'@ style/theme.appcompat匹配的资源。 light.darkactionbar'in styles.xml – Michal

+0

您的应用程序是否与支持库正确链接? (有资源,如下所示:https://developer.android.com/tools/support-library/setup.html#add-library) – Shlublu

0

如果你在你的清单做这个,做以下设置主题为整个应用程序:

<application 
    ... 
    android:theme="@style/Theme.AppCompat.Light.DarkActionBar" 
    ...> 

在您的XML为特定主题,您需要@style,所以把以下内容:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> 
+0

我得到:没有找到与styles.xml中给定名称'@ style/theme.appcompat.light.darkactionbar'匹配的资源 – Michal