android - 找不到与给定名称 attr "colorPrimary"匹配的资源

标签 android xamarin xamarin.android

我很难在 Xamarin Studio 中编译我的 Android 应用程序。出现的错误如下:

No resource found that matches the given name attr "colorPrimary"

它指的是我的 styles.xml:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <!--item name="colorPrimaryDark">@color/colorPrimaryDark</item-->
        <!--item name="colorAccent">@color/colorAccent</item-->
    </style>
</resources>

在网上找到的通常建议是将 SDK 版本设置为 21 或更高版本。但我已经尝试过了:

  • 在 list 中将 minSdkVersion 设置为 21
  • 在 list 中将 targetSdkVersion 设置为 21
  • 在项目设置中将目标框架设置为 Android 5.0
  • 清理并重建项目

错误仍然存​​在:-( 是否需要其他设置才能使其正常工作?

最佳答案

这对我的项目有用。

res/values-v21/styles.xml中,

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="AppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
    <item name="android:colorPrimary">@color/primaryColor</item>
    </style>
</resources>

res/values/styles.xml中,

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/primaryColor</item>
    </style>
</resources>

关于android - 找不到与给定名称 attr "colorPrimary"匹配的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38996638/

相关文章:

android - 目标选项在 Eclipse 窗口->首选项->android 中被禁用

ios - 如何在 Interface Builder 文件中使用自定义 iOS View (位于引用的类库中)?

ios - 从 visual studio 2013 运行 xamarin.ios 应用程序?

json - Google 云视觉 - 从 OCR 请求获取 JSON 错误响应

mvvm - MvvmCross:如何在Android上从常规 View 导航到Mvvm View 模型?

c# - xamarin - ImageView 在从画廊的相机拍摄照片后显示黑色图像

java - 将按钮的图像设置为应用程序图标

Android One 作为信标发射器

java:将动画向上转换为 CustomAnimation 时出现 ClassCastException

iOS Xamarin UIView 基于父级填充