简体   繁体   中英

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. I want to achieve this using the v7 AppCompat library, so my app runs well on older devices.

I followed this tutorial:

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). 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 .

EDIT(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. I also removed the \\AppData\\Local\\Xamarin\\Android.Support.v7.AppCompat\\23.0.1.3 folder and removed the cache, but without succes.

And at the Main.axml file in the designer tab, appears a warning:

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. So I asked a new question: Xamarin.Android, Visual Studio - Designer doesn't work with v7 AppCompat library

Here you can download my project:

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.

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.

See Xamarin.Android, Visual Studio - Designer doesn't work with v7 AppCompat library for more detailed answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM