android - xamarin NavigationView 给出错误,找不到应用程序 :headerLayout 的资源

标签 android xamarin mvvmcross android-appcompat

我正在尝试在我的 Xamarin Android 项目中设置 NavigationView。我的 Main.axml 文件结构如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <include
            layout="@layout/toolbar" />
        <FrameLayout
            android:id="@+id/frameLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/navmenu"
        app:headerLayout="@layout/headerdrawerlayout" />
</android.support.v4.widget.DrawerLayout>

在我的 packages.config 中,我有 AppCompat 包(以及其他包):

<package id="MvvmCross.Droid.Support.V7.AppCompat" version="4.1.7" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="23.3.0" targetFramework="monoandroid60" />

我得到编译器错误:

No resource identifier found for attribute 'headerLayout' in package 'mycompany.myapp'  myapp.Android   C:\Users\JP\Documents\Visual Studio 2015\Projects\MyApp\MyApp.Android\Resources\layout\Main.axml    

Resource.designer.cs 文件不应该自动引入这些属性吗?我必须承认我有点不确定这个过程是如何运作的。会不会是某个地方的版本冲突? res-auto 如何适应一切?

如有任何帮助,我们将不胜感激。

最佳答案

确保您安装了 Android 设计支持库。

你可以通过nuget得到它(或 Xamarin Component store ):

Install-Package Xamarin.Android.Support.Design

DrawerLayout 是 Android 支持库的一项功能,它依赖于设计支持库,因为它是一种 Material 设计控件。许多 Android 支持库对设计支持库没有硬性依赖,因为在 API 21 (Lollipop) 之前支持 Material 设计是可选的。然而,关于 DrawerLayout 它是一个 required despency .

Support libraries provide user interface elements not offered by the Android framework. For example, the Android Support Library offers additional layout classes, like DrawerLayout. These classes follow recommended Android design practices; for example, the Design Library follows the principles of material design in a way that works across many versions of Android.

headerLayout 如何包含在您的 Resource.Designer.cs

如果您在 Android SDK 文件夹中查找文件 attrs.xml(并包含 Extras: Android Support Repository):

android-sdk\extras\android\support\design\res\values\attrs.xml

您将能够在该文件中搜索 headerLayout declare-styleable 属性。当您包含设计支持库时,所有各种 XML 标记都将被引用为常量,然后您可以在后面的代码中使用。

关于android - xamarin NavigationView 给出错误,找不到应用程序 :headerLayout 的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37625239/

相关文章:

android - ANDROID_ID 在 2013/4.x 中仍然不可靠吗?

eclipse - 为什么 Eclipse 看不到我的 Samsung Galaxy 手机,即使我可以使用驱动器盘符传输文件?

c# - Xamarin 加载操作失败

android - 从 ViewModel 中的列表中搜索(Xamarin Android)

安卓彩信广播接收器

Android 电子市场/Google Play 网址

ios - iPhone - 一个 View 中的多个表

android - Monodroid - 如何调试 android 小部件

ios - 将 Google 移动分析与 MVVMCross 集成

xamarin.android - 如何使用 MvvmCross 框架使用 MonoDroid TabActivity