Android.Views.InflateException: binary string of XML file # 17: error inflating class android.support.design.internal.NavigationMenuItemView

I use the material navigation box in my android project using Xamarin. I am trying to add two Framelayouts to drawerlayout so that I can switch 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> 

Primary 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 line of XML file # 17: bloat error of android.support.design.internal.NavigationMenuItemView class

I tried moving elements in Drawerlayout, but the error is persistent. I looked at the documentation on Android, everything seems to be correct. I also verified that I have the latest version of the Design library and AppCompact

+5
source share
5 answers

I encountered the same problem a while ago, I don’t know exactly what caused it, but I can tell you what I did, maybe this can help you.

  • My phone memory was almost full, so I deleted several applications
  • I uninstalled the application that threw an error
  • I cleaned and rebuilt the project
  • Try again.

Voila! It worked.

+24
source

I may be late, but I have the same error. So, on AndroidStudio, I just cleaned up my project (" Clean Projet "). After that, I was able to start my project again without this error.

+5
source

The error is due to the fact that you can extend MainActivity to Activity instead of AppComptActivity

If you use any components of the Design Library, you must make sure that your activity extends AppCompatActivity and uses the appropriate Theme.AppCompat theme. Note that FloatingActionButton relies on the colorAccent set on your theme - make sure your theme is defined.

+1
source

I try to fulfill my decision, and this led to success: 1. Clear temp on C drive (disk installation operating system) 2. Reconstruction of the project 3. Paste into the head activity [Activity (topic = "@ style / MyTheme")] public class viewDetailsActivity: BaseActivity {.....} 4. Project execution Note: insert the style.xml file in 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 that I do not speak English well, but success solves the problem

0
source

A quick note about the exception: The exception also occurs if the content layout is not added to DrawerLayout , so be sure to add it.

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> 
0
source

Source: https://habr.com/ru/post/1244721/


All Articles