找不到与给定名称“android:Theme.Material”匹配的资源

时间:2014-09-05 14:37:53

标签: android material-design

阅读this answer后,我在Android 3.0+上运行了RecyclerView。但styles.xml中的values-v21仍会导致错误。

主题。

<!-- 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>

错误。

  

错误:检索项目的父项时出错:找不到匹配的资源   给定名称&#39; android:Theme.Material&#39;。

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

2 个答案:

答案 0 :(得分:2)

仅从API级别21支持

android:Theme.Material。您可以在android studio中看到错误消息,如下所示:

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

答案 1 :(得分:1)

如果您使用支持库,您可以安全地使用这些属性,它们将起作用(尽可能多的操作系统允许):

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

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

您也可以使用其他人:

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