【问题标题】:Xamarin: Error retrieveing parent for item CardViewXamarin:检索项 CardView 的父项时出错
【发布时间】:2015-10-12 16:54:14
【问题描述】:

设置

我对 Xamarin 很陌生,我正在尝试遵循官方文档并在虚拟应用中实现 Lollipop Material Design Style

我已经添加了该 repo 中出现的资源:

(事实证明,values-v21 是正确的文件夹名称,与 repo 上的不同)

然后我还从 SDK 管理器安装了整个 Android API 21 文件夹,还安装了 NuGet Xamarin.Android.Support.v7.AppCompat,它在我的 packages.config AFAIK 中正确显示:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Xamarin.Android.Support.v4" version="23.0.1.1" targetFramework="MonoAndroid50" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="23.0.1.1" targetFramework="MonoAndroid50" />
</packages>

错误

但是当我点击播放(以 API 21 作为目标的调试模式)时,我收到以下三个错误:

Build FAILED.
Errors:

/Users/pegasus/Projects/DistraeMe/DistraeMe/DistraeMe.csproj (Build) ->
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets (_UpdateAndroidResgen target) ->

    Resources/values-v21/styles.xml(2): error APT0000: Error retrieving parent for item: No resource found that matches the given name 'CardView'.
    Resources/values-v21/styles.xml(2): error APT0000: No resource found that matches the given name: attr 'cardBackgroundColor'.
    Resources/values-v21/styles.xml(2): error APT0000: No resource found that matches the given name: attr 'cardCornerRadius'.

这是从 repo 中粘贴的 styles.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
  <!-- Define a custom theme that derives from the light Material Theme -->
  <style name="MyCustomTheme" parent="android:Theme.Material.Light">

    <!-- Override the app bar color -->
    <item name="android:colorPrimary">@color/my_blue</item>

    <!-- Override the color of UI controls -->
    <item name="android:colorAccent">@color/my_purple</item>

  </style>

  <!-- Theme an individual view: -->
  <style name="CardView.MyBlue">

    <!-- Change the background color to Xamarin blue: -->
    <item name="cardBackgroundColor">@color/my_blue</item>

    <!-- Make the corners very round: -->
    <item name="cardCornerRadius">18dp</item>
   </style>
</resources>

我没有正确链接这些资源吗?我做错了什么?

【问题讨论】:

    标签: android xamarin xamarin.forms xamarin-studio


    【解决方案1】:

    检查可能导致问题的几件事:

    1) 如果您使用 AppCompat 控件/活动,请使用 Theme.AppCompat.Light 而不是 Theme.Material.Light

    2) 您的活动是否继承自 AppCompatActivity

    3) 设置 CardView 样式的父级为parent="CardView"

    希望有帮助!

    【讨论】:

      【解决方案2】:

      截至 2019 年,我收到了相同的错误消息;

      error APT0000: Error retrieving parent for item: No resource found that matches the given name 'CardView'.
      error APT0000: No resource found that matches the given name: attr 'cardBackgroundColor'.
      error APT0000: No resource found that matches the given name: attr 'cardCornerRadius'.
      

      解决办法: 我只需要添加 nuget 包 Xamarin.Android.Support.v7.CardView

      【讨论】:

        猜你喜欢
        • 2016-08-15
        • 2016-03-04
        • 2015-02-10
        • 1970-01-01
        • 2016-02-26
        • 1970-01-01
        • 1970-01-01
        • 2014-12-22
        • 2016-07-23
        相关资源
        最近更新 更多