我是Xamarin的新手,我正在尝试遵循官方文档,并在虚拟应用程序中实现Lollipop Material Design Style。
我添加了该回购中显示的资源:
(事实证明,values-v21
是正确的文件夹名称,与回购时不同)
然后我还从SDK管理器安装了整个Android API 21文件夹,并安装了我的packages.config AFAIK中正确显示的NuGet Xamarin.Android.Support.v7.AppCompat
:
<?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>
我没有正确链接这些资源吗?我做错了什么?
答案 0 :(得分:2)
要检查的一些事情可能导致问题:
1)如果您正在使用AppCompat控件/活动,请使用Theme.AppCompat.Light
代替Theme.Material.Light
2)您的活动是否继承自AppCompatActivity
?
3)将CardView样式的父级设置为parent="CardView"
希望有所帮助!
答案 1 :(得分:0)
截至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