Android.Views.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView

Viewed 10860

I am using a material navigation drawer in my android project using Xamarin. I have been trying to add two Framelayouts into the drawerlayout so that I can switch the content from different fragments see below xml:

 <?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/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
      <!-- This LinearLayout represents the contents of the screen  -->
      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">
        <!-- The ActionBar displayed at the top -->
        <include
            layout="@layout/toolbar"
android:id="@+id/toolbar" />
        <!-- The main content view where fragments are loaded -->
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:id="@+id/scrollview">
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">
            <FrameLayout
                android:id="@+id/search_frame"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@+id/blah"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
          </LinearLayout>
        </ScrollView>
      </LinearLayout>
      <!-- The navigation drawer that comes from the left -->
      <!-- Note that `android:layout_gravity` needs to be set to 'start' -->
      <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/drawer_view"
          app:itemTextColor="#FFFFFF"
          app:itemIconTint="#FFFFFF"
          android:background="#464646"/>
    </android.support.v4.widget.DrawerLayout>

The main activity :

protected override void OnCreate(Android_OS.Bundle bundle)
{
    base.OnCreate(bundle);

    SetContentView(Resource.Layout.activity_main);

    drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
    // Setting up the toolbar
    var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
    SetSupportActionBar(toolbar);
    SupportActionBar.SetTitle(Resource.String.ApplicationName);
    SupportActionBar.SetDisplayHomeAsUpEnabled(true);
    SupportActionBar.SetDisplayShowHomeEnabled(true);

    // Attach item selected handler to navigation view
    var navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
    navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;

    // Create ActionBarDrawerToggle button and add it to the toolbar
    var drawerToggle = new Android_Support.V7.App.ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.open_drawer, Resource.String.close_drawer);
    drawerLayout.SetDrawerListener(drawerToggle);
    drawerToggle.SyncState();
}

I get the following error: Android.Views.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView

I have tried moving the elements in the Drawerlayout but the error is persistent. I have looked at the Android documentation everything seems correct. I have also checked that I have the most recent version of both the Design and AppCompact library

8 Answers
  1. Delete everything in your project's bin folder.
  2. Delete everything in your project's obj folder.
  3. Run Build->Clean Solution
  4. Then try to build and run your solution again.

Just cleaning the solution wasn't enough for me; I had to manually remove everything in the bin and obj folders to get up and running again.

I just had this issue. All I needed to do was Right click on my Android solution → Properties → Android Options → set Linking to None.

I fixed it by right clicking android project -> Properties -> Android Options and selecting nothing at the Code shrinker.

Related