2016-08-16 36 views
3

我想使用Xamarin和Visual Studio创建一个包含Material Design的应用程序。我想用v7 AppCompat库来实现这个功能,所以我的应用程序在旧设备上运行良好。Xamarin - 检索项目的父项时出错:未找到与给定名称相匹配的资源'Theme.AppCompat.Light.DarkActionBar'

我跟着这个教程:

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

EDIT(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设计,因为它可以正常运行我的手机上。于是我问了一个新问题:Xamarin.Android, Visual Studio - Designer doesn't work with v7 AppCompat library

在这里,您可以下载我的项目:

https://drive.google.com/file/d/0BxiDy9-wQHvzNFRhaTMzelg1WlU/view?usp=sharing

(对不起,我英文不好,随时纠正我)

+0

为了更好的理解问题,粘贴代码。 –

+1

你在哪里应用主题?在你的'AndroidManifest.xml'中?尝试核弹'bin/obj'文件夹,清理项目和重建。请确保你的'v7 AppCompat' NuGet包被适当引用。 –

+0

@JonDouglas我在'AndroidManifest.xml'中应用主题。我加入了'bin'和'obj'文件夹。我清理并重建了我的物体。我得到了和以前一样的错误:'错误检索项目的父项:找不到与给定名称'Theme.AppCompat.Light.DarkActionBar'.'匹配的资源(在我的问题的顶部有更多细节)。当我重新编译时,出现这个错误:'1> java.lang.UnsupportedClassVersionError:com/android/dx/command/Main:Unsupported major.minor version 52.0'(更多细节请参阅我的问题的编辑(2) 。所以不幸的是它不起作用:( – qwertytrewq

回答

相关问题