简体   繁体   English

Xamarin-检索项目的父项时出错:找不到与给定名称'Theme.AppCompat.Light.DarkActionBar'匹配的资源

[英]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.

相关问题 检索项目的父项时出错:找不到与给定名称“ThemeOverlay.AppCompat.Light”匹配的资源 - Error retrieving parent for item: No resource found that matches the given name 'ThemeOverlay.AppCompat.Light' 在Xamarin.Android中找不到与给定名称匹配的资源(在&#39;headerLayout&#39;处) - No resource found that matches the given name (at 'headerLayout') in Xamarin.Android 设置Xamarin.Forms-“找不到与给定名称匹配的资源...” - Setup Xamarin.Forms - “No resource found that matches the given name…” 如何修复Xamarin android c#中的“找不到与给定名称(在&#39;value&#39;处与值&#39;@ integer / google_play_services_version匹配)的资源” - How to fix“No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version)” in Xamarin android c# 找不到与给定名称Styles.xml匹配的资源 - No resource found that matches the given name Styles.xml 没有找到与给定名称匹配的资源,我在哪里做错了? - No resource found that matches the given name, where I do something wrong? 找不到与给定名称匹配的资源 - No resource found that matches the given names 找不到与给定名称匹配的资源(在&#39;src&#39;处,值为&#39;@android:drawable / logo.png - No resource found that matches the given name (at 'src' with value '@android:drawable/logo.png 找不到与common_signin_btn_icon_dark.xml中的给定名称匹配的资源 - No resource found that matches the given name in common_signin_btn_icon_dark.xml 从项目中检索父项时出错 - Error retrieving parent from item
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM