4

I'm creating Android app using Xamarin for Android. I want to use in my app NavigationDrawer, so I downloaded and installed 'Android Design Library' from Xamarin Components Store. Then I edited my layout for 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_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/articlesListView" />
    <android.support.design.widget.NavigationView
        android:id="@+id/navView"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/navHeader"
        app:menu="@menu/navMenu"/>
</android.support.v4.widget.DrawerLayout>

navHeader.axml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="192dp"
    android:background="?attr/colorPrimaryDark"
    android:padding="16dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    android:orientation="vertical"
    android:gravity="bottom">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>

</LinearLayout>

and menu/navMenu.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
  <group android:checkableBehavior="single">
    <item
      android:id="@+id/nav_home"
      android:title="Home" />
    <item
      android:id="@+id/nav_messages"
      android:title="Messages" />
    <item
      android:id="@+id/nav_friends"
      android:title="Friends" />
    <item
      android:id="@+id/nav_discussion"
      android:title="Discussion" />
  </group>
  <item android:title="Sub items">
    <menu>
      <item
        android:title="Sub item 1" />
      <item
        android:title="Sub item 2" />
     </menu>
  </item>
</menu>

Unfortunately while compiling, I received following error:

C:\Project\Project\File.axml: Error APT0000: No resource found that matches the given name (at 'headerLayout' with value '@layout/navHeader'). (APT0000) (AppName) C:\Projects\Project\File.axml(0,0): Error APT0000: No resource found that matches the given name (at 'menu' with value '@menu/navMenu'). (APT0000) (AppName)

Somebody knows how I may solved this problem?

Thank you in advance

4
  • Can you post the directory structure of your .axml files? All layouts should be in Resources/layout/ and menus should be in Resources/menu/
    – woot
    Commented Nov 2, 2015 at 17:44
  • All layouts are in Resources/layout folder and navMenu.xml is in Resources/menu folder
    – Jake
    Commented Nov 2, 2015 at 17:47
  • I'm not certain of this, but I believe navMenu.xml should actually be navMenu.axml (I use .axml for all my menus) - can you rename and see if that fixes the problem?
    – woot
    Commented Nov 2, 2015 at 19:27
  • Same issue, does anyone have an answer?
    – Steph
    Commented Jul 16, 2016 at 17:51

3 Answers 3

9

I had the same issue. I simply put lower case letters in the name of the header layout file and it worked.

Before (Failing with same error message):

app:headerLayout="@layout/DrawerHeader"

After:

app:headerLayout="@layout/drawerheader"
1
  • 2
    Doesn't work for me. seems like huge bug in Xamarin! Commented Jan 7, 2018 at 12:57
1

Named Your layout file and menu with the small letter.

app:headerLayout="@layout/drawerheader"
app:menu="@menu/drawermenu"
1
  • This was my issue too. Uppercase names work for other resources, but not all of them I guess.
    – Dave
    Commented Oct 17, 2017 at 17:17
0

Had the same problem. Guess it is a bug. C# code addition (in OnCreate() method of your activity) of navigation header view and menu view works fine for me. That is done with NavigationView methods InflateMenu and inflateHeaderView.

EDIT


First delete

app:headerLayout="@layout/navHeader"

and

app:menu="@menu/navMenu"

from your Navigation Drawer layout and insert

navigationView = FindViewById<NavigationView>(Resource.Id.navView);    
navigationView.InflateHeaderView(Resource.Layout.navHeader);
navigationView.InflateMenu(Resource.Menu.navMenu);

somewhere in onCreate() method of your activity in question.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.