检索项的父项时出错:未找到与给定名称匹配的资源';Android:Theme.Material';
我正在尝试将检索项的父项时出错:未找到与给定名称匹配的资源';Android:Theme.Material';,android,Android,我正在尝试将材料主题与以下代码一起使用 My styles.xml文件 <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="
材料主题
与以下代码一起使用
My styles.xml文件
<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="Theme.AppCompat.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="Android:Theme.Material">
<item name="android:colorPrimary">@color/primary</item>
</style>
</resources>
这有什么问题?设置
android:minSdkVersion=“L”android:targetSdkVersion=“L”
您需要执行以下步骤
设置为“android-L”compileSdkVersion
设置为“L”minSdkVersion
设置为“L”targetSdkVersion
阅读更多关于的信息,按照以下步骤操作 1.首先,在res/values文件夹名(color.xml)中定义一个新的xml文件。 2.然后将自定义颜色定义为
<resources>
<color name="primary">#03f</color>
</resources>
#03f
问题是你的主题提供了一个定制的地方,但是它不知道@color/primary这个东西
现在再次尝试运行该项目
请记住设置android:minSdkVersion=“L”android:targetSdkVersion=“L”在撰写本文时@Pankaj的答案是正确的。现在API21正式发布了,有些地方发生了变化 要在项目中使用材质主题,您必须:
- 使用API 21进行编译(这是必需的)
- 使用minSdkVersion=21和values文件夹
- 仅在values-v21文件夹中使用Theme.Material
- 在values文件夹中使用AppCompat主题
styles.xml中打开AppTheme
,然后上传它们的内容。什么是您的目标sdk到项目属性中?android:minSdkVersion=“21”android:targetSdkVersion=“21”
<resources>
<color name="primary">#03f</color>
</resources>