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

10,786

Solution 1

I was facing the same problem some time back, I don't know exactly what caused it, but I can tell you what I did, maybe it can help you.

  1. My phone memory was almost full, so I deleted some apps
  2. I uninstalled the app which was giving the error
  3. I cleaned and rebuilt the project
  4. Ran it again.

Voila! It worked.

Solution 2

I may be late, but i just got the same error. So on AndroidStudio, i just cleaned my project ("Clean Projet"). After that i was able to run my project once again without that error.

Solution 3

A quick remark regarding the exception: The exception occurs also if no content layout has been added to the DrawerLayout, so be sure to add one.

An example:

<?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/activity_main_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <!-- Start of content -->
    <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
    <include
        layout="@layout/toolbar"
        android:id="@+id/toolbar" />
    </LinearLayout>
    <!-- End of content -->

<android.support.design.widget.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:id="@+id/activity_main_navigation_view"
    app:menu="@menu/menu_activity_main_navigation" />
</android.support.v4.widget.DrawerLayout>

Solution 4

I try my solution and it did running success: 1. Clear temp on disk C(disk setup opera system) 2. Rebuild project 3. Insert in to head activity [Activity(Theme = "@style/MyTheme")] public class viewDetailsActivity : BaseActivity {.....} 4. Running Project Note: insert file style.xml this code

     <style name="MyTheme" parent="MyTheme.Base">
    <item name="android:textColor">@color/black</item>
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">@color/primary</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">@color/primaryDark</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">@color/accent</item>
    <!-- You can also set colorControlNormal, colorControlActivated-
         colorControlHighlight and colorSwitchThumbNormal. -->

    <!-- Option to hide the drop shadow here

      <item name="actionBarStyle">@style/MyTheme.ActionBar</item>
      <item name="android:windowContentOverlay">@null</item>
    -->
  </style>
  <style name="MyTheme.NoActionBar">
    <!-- Both of these are needed -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
  </style>
  <style name="MyTheme.ActionBar" parent="style/Widget.AppCompat.Light.ActionBar.Solid">
    <!-- remove shadow below action bar -->
    <!-- <item name="android:elevation">0dp</item> -->
    <!-- Support library compatibility -->
    <item name="elevation">0dp</item>
    <item name="android:background">@color/pictonBlue</item>
  </style>

I think i talk English not good, but problem solve success

Share:
10,786
George
Author by

George

Updated on June 07, 2022

Comments

  • George
    George about 2 years

    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

  • Sufian
    Sufian almost 8 years
    Are you seriously sure that this exception gets thrown because of low memory? And that it can be fixed up uninstalling few apps?
  • Harshit Kumar
    Harshit Kumar almost 8 years
    It worked with me, I never said it was the correct answer
  • Jonathan Perry
    Jonathan Perry almost 8 years
    This worked for me too, but my guess is only step 3 fixed the problem. Anyways, thanks!
  • Ravindra Kumar
    Ravindra Kumar almost 8 years
    yeah! i spend a day in googling and I am wondering, it worked for me as well.
  • Carol AndorMarten Liebster
    Carol AndorMarten Liebster over 7 years
    #3 for me as well
  • wainy
    wainy about 7 years
    #3 for me too. Strangely it was specifically a Clean and then a Rebuild. Clean + Debug didn't work, neither did Clean + Build. Thanks.
  • Richard Rout
    Richard Rout over 6 years
    Is there no better solution than this? I get this problem 3-4 times a day. Clean Build seems to only fix it for a short time.
  • amitavk
    amitavk about 5 years
    #2 was the fix for me