Reputation: 349
I am trying to set up the NavigationView in my Xamarin Android project. I have the Main.axml file structured like this:
<?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>
in my packages.config, I have the AppCompat packages (among others):
<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" />
I get the compiler error:
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
Shouldn't the Resource.designer.cs file automatically bring in these attributes? I must admit to being a little bit unsure of how that process works. Could it be a version conflict somewhere? How does the res-auto fit into everything?
Any help would be appreciated.
Upvotes: 2
Views: 1278
Reputation: 5192
Make sure that you have Android Design Support Library installed.
You can get it via nuget (or Xamarin Component store):
Install-Package Xamarin.Android.Support.Design
The DrawerLayout
is a feature of Android Support Library with a dependency on the Design Support Library as it is a material design control. Many of the Android Support Libraries do not have a hard dependency on the Design Support Library due to the fact that supporting material design on pre API 21 (Lollipop) is optional. However, with respect to the DrawerLayout
it is a 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.
How headerLayout
will get include in your Resource.Designer.cs
If you look in your Android SDK folder (And have included Extras: Android Support Repository) for the file attrs.xml
:
android-sdk\extras\android\support\design\res\values\attrs.xml
You will be able to search this file for the headerLayout
declare-styleable attribute. When you include the Design Support Library all the various XML tag will be referenced into constants you can then make use of in your code behind.
Upvotes: 6