xamarin NavigationView 给出错误,未找到 app:headerLayout 的资源
xamarin NavigationView gives error no resource found for app:headerLayout
我正在尝试在我的 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 (or 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
:
android-sdk\extras\android\support\design\res\values\attrs.xml
您将能够在该文件中搜索 headerLayout
declare-styleable 属性。当您包含设计支持库时,所有各种 XML 标记都将被引用为常量,然后您可以在后面的代码中使用它。
我正在尝试在我的 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 (or 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
:
android-sdk\extras\android\support\design\res\values\attrs.xml
您将能够在该文件中搜索 headerLayout
declare-styleable 属性。当您包含设计支持库时,所有各种 XML 标记都将被引用为常量,然后您可以在后面的代码中使用它。