![](/img/trans.png)
[英]Error retrieving parent for item: No resource found that matches the given name 'ThemeOverlay.AppCompat.Light'
[英]Xamarin - Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'
我想使用Xamarin和Visual Studio使用Material Design创建一个应用程序。 我想使用v7 AppCompat库来实现此目的,因此我的应用在旧设备上可以很好地运行。
我遵循了本教程:
https://blog.xamarin.com/android-tips-hello-material-design-v7-appcompat/
并完全一样。 当我转到Main.axml
文件(在Resources/layout
文件夹中)时,有一个下拉菜单,您可以在其中选择主题(下图)。 但是,当我打开下拉菜单时,我的主题没有出现。 因此,我认为清理并重建项目是一个好主意。 但是当我清理项目时,出现了以下错误:
Error retrieving parent for item: No resource found that matches the given
name 'Theme.AppCompat.Light.DarkActionBar'.
No resource found that matches the given name: attr 'colorAccent'.
No resource found that matches the given name: attr 'colorPrimary'.
No resource found that matches the given name: attr 'colorPrimaryDark'.
No resource found that matches the given name: attr 'windowActionBar'.
No resource found that matches the given name: attr 'windowNoTitle'.
如何修复它并使主题出现在下拉菜单中?
编辑:
这是代码:
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/MyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Hello" />
</LinearLayout>
values/styles.xml
<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#2196F3</item>
<item name="colorPrimaryDark">#1976D2</item>
<item name="colorAccent">#FF4081</item>
</style>
</resources>
values-v21
<resources>
<style name="MyTheme" parent="MyTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>
</resources>
MainActivity.cs
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace MaterialDesign
{
[Activity(Label = "MaterialDesign", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
}
}
}
注意:
另外,当我使用android.support.v7.widget.Toolbar
元素时,出现以下错误: android.support.v7.widget.Toolbar element is not declared
。
编辑(2):
我尝试使用组件管理器和NuGet命令(软件包管理器控制台)下载它,然后手动下载dll并引用它们,但是仍然无法正常工作。 我还删除了\\AppData\\Local\\Xamarin\\Android.Support.v7.AppCompat\\23.0.1.3
文件夹并删除了缓存,但是没有成功。
在设计器选项卡的Main.axml
文件中,显示警告:
This project contains resources that were not compiled successfully,
rendering might be affected
我发现问题出在Visual Studio Designer,因为它可以在手机上正常运行。 所以我问了一个新问题: Xamarin.Android,Visual Studio-Designer无法与v7 AppCompat库一起使用
在这里您可以下载我的项目:
https://drive.google.com/file/d/0BxiDy9-wQHvzNFRhaTMzelg1WlU/view?usp=sharing
(对不起,英语不好,请随时纠正我)
它与代码无关。 只是在撰写本文时,Visual Studio不支持自定义视图。
只需使用Xamarin Studio或此插件https://visualstudiogallery.msdn.microsoft.com/9f5a516a-f4d0-4228-9d25-d0273abebf33 ,即可在Android Studio中编辑应用程序。
有关更详细的答案,请参见Xamarin.Android,Visual Studio-Designer不与v7 AppCompat库一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.