[英]Xamarin - Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'
I want to create an app with Material Design using Xamarin and Visual Studio. 我想使用Xamarin和Visual Studio使用Material Design创建一个应用程序。 I want to achieve this using the v7 AppCompat library, so my app runs well on older devices.
我想使用v7 AppCompat库来实现此目的,因此我的应用在旧设备上可以很好地运行。
I followed this tutorial: 我遵循了本教程:
https://blog.xamarin.com/android-tips-hello-material-design-v7-appcompat/ https://blog.xamarin.com/android-tips-hello-material-design-v7-appcompat/
and did exact the same. 并完全一样。 When I go to the
Main.axml
file(in the Resources/layout
folder) there's a dropdown menu where you can select a theme(picture below). 当我转到
Main.axml
文件(在Resources/layout
文件夹中)时,有一个下拉菜单,您可以在其中选择主题(下图)。 However, when I open the dropdown menu, my theme doesn't appear. 但是,当我打开下拉菜单时,我的主题没有出现。 So I thought it was a good idea to clean and rebuild my project.
因此,我认为清理并重建项目是一个好主意。 But when I cleaned the project, I got this error:
但是当我清理项目时,出现了以下错误:
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'.
How can I fix it and make my theme appear in the dropdown menu? 如何修复它并使主题出现在下拉菜单中?
EDIT: 编辑:
Here's the code: 这是代码:
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++); };
}
}
}
NOTE: 注意:
Also when I am using the android.support.v7.widget.Toolbar
element, I got the following error: android.support.v7.widget.Toolbar element is not declared
. 另外,当我使用
android.support.v7.widget.Toolbar
元素时,出现以下错误: android.support.v7.widget.Toolbar element is not declared
。
EDIT(2): 编辑(2):
I tried downloading it with the component manager, with a NuGet command(Package Manager Console) and manually download the dll's and reference them, but it still didn't work. 我尝试使用组件管理器和NuGet命令(软件包管理器控制台)下载它,然后手动下载dll并引用它们,但是仍然无法正常工作。 I also removed the
\\AppData\\Local\\Xamarin\\Android.Support.v7.AppCompat\\23.0.1.3
folder and removed the cache, but without succes. 我还删除了
\\AppData\\Local\\Xamarin\\Android.Support.v7.AppCompat\\23.0.1.3
文件夹并删除了缓存,但是没有成功。
And at the Main.axml
file in the designer tab, appears a warning: 在设计器选项卡的
Main.axml
文件中,显示警告:
This project contains resources that were not compiled successfully,
rendering might be affected
I found out that the problem is with Visual Studio Designer, as it runs properly on my phone. 我发现问题出在Visual Studio Designer,因为它可以在手机上正常运行。 So I asked a new question: Xamarin.Android, Visual Studio - Designer doesn't work with v7 AppCompat library
所以我问了一个新问题: Xamarin.Android,Visual Studio-Designer无法与v7 AppCompat库一起使用
Here you can download my project: 在这里您可以下载我的项目:
https://drive.google.com/file/d/0BxiDy9-wQHvzNFRhaTMzelg1WlU/view?usp=sharing https://drive.google.com/file/d/0BxiDy9-wQHvzNFRhaTMzelg1WlU/view?usp=sharing
(Sorry for bad English, feel free to correct me) (对不起,英语不好,请随时纠正我)
It had nothing to do with the code. 它与代码无关。 It's just that Visual Studio at moment of writing doesn't support Custom Views.
只是在撰写本文时,Visual Studio不支持自定义视图。
Just use Xamarin Studio or this plugin https://visualstudiogallery.msdn.microsoft.com/9f5a516a-f4d0-4228-9d25-d0273abebf33 So you can edit your applications in Android Studio. 只需使用Xamarin Studio或此插件https://visualstudiogallery.msdn.microsoft.com/9f5a516a-f4d0-4228-9d25-d0273abebf33 ,即可在Android Studio中编辑应用程序。
See Xamarin.Android, Visual Studio - Designer doesn't work with v7 AppCompat library for more detailed answers. 有关更详细的答案,请参见Xamarin.Android,Visual Studio-Designer不与v7 AppCompat库一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.