2014-09-05 63 views
5

看完this answer后,我制作了RecyclerView在Android 3.0+上运行。但在values-v21中的styles.xml仍然会导致错误。找不到符合指定名称的资源'android:Theme.Material'

主题。

<!-- inherit from the material theme --> 
<style name="AppTheme" parent="android:Theme.Material"> 

    <!-- Main theme colors --> 
    <!-- your app's branding color (for the app bar) --> 
    <item name="android:colorPrimary">#f00</item> 
    <!-- darker variant of colorPrimary (for status bar, contextual app bars) --> 
    <item name="android:colorPrimaryDark">#0f0</item> 
    <!-- theme UI controls like checkboxes and text fields --> 
    <item name="android:colorAccent">#00f</item> 
</style> 

错误。

Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material'.

我需要从Android 3.0.x(API级别11)支持Android版本。 <uses-sdk android:minSdkVersion="L" android:targetSdkVersion="L" />不是一个解决方案。

android.Theme.Material requires API level 21(current min is 14) 
+0

在两个不同的文件夹中有两个不同的style.xml文件。值-V20和值 – hoomi 2014-09-05 14:45:04

+0

@hoomi,我已经有'values'和'values-v21'。 'android:Theme.Material'会导致错误。 – 2014-09-05 14:52:57

+1

android:Theme.Material仅支持API级别20. – Psypher 2014-09-05 14:57:45

回答

2

android:Theme.Material只从API级别21.您可以看到在Android Studio中,如下错误消息支持(不亚于操作系统允许):

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

    <item name="colorPrimary">...</item> 
</style> 

您还可以使用其他:

<item name="colorPrimaryDark">...</item> 
    <item name="colorAccent">...</item> 
+0

好的,让我们使用'android.Theme.Material'来学习它,并希望从Google – 2014-09-05 15:55:46

+1

获得修复,这意味着在Android Studio中,该项目 - >右键单击 - >打开模块设置 - >在模块下,选择您的项目 - >编译SDK版本必须是API 21 – 2014-12-24 00:48:54

1

如果使用支持库,你可以放心地使用这些属性,它们将工作:

相关问题