Alexander Mujirishvili
Alexander Mujirishvili

Reputation: 365

Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.v7.widget.DrawerLayout

I am new to android apps development and I am trying to add navigation to my app, but I am getting this error on SetContentView(Resource.Layout.activity_working); in WorkingActivity.cs:

Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.v7.widget.DrawerLayout

These are my files:

activity_working.axml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"    
  android:orientation="vertical"    
  android:layout_width="match_parent"    
  android:layout_height="match_parent">    
  <android.support.v7.widget.DrawerLayout xmlns:app="http://schemas.android.com/apk/res-auto"    
     android:id="@+id/drawer_layout"    
     android:layout_height="match_parent"    
     android:layout_width="fill_parent"    
     android:fitsSystemWindows="true">    
         <LinearLayout    
            android:layout_width="match_parent"    
            android:layout_height="match_parent"    
            android:orientation="vertical">    
          <include layout="@layout/toolbar" />    
  </LinearLayout>

  <android.support.design.widget.NavigationView    
     android:id="@+id/nav_view"    
     android:layout_height="match_parent"    
     android:layout_width="300dp"    
     android:layout_gravity="start"   
     android:fitsSystemWindows="true"
     app:headerLayout="@layout/nav_header" />   
  </android.support.v7.widget.DrawerLayout>   

WorkingActivity.cs

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Support.V4.Widget;
using Android.Support.V7.App;
using Android.Support.V7.Widget;
using Android.Views;
using Android.Widget;

namespace App2
{
    [Activity(Label = "WorkingActivity", Theme = "@style/AppTheme")]
    public class WorkingActivity : AppCompatActivity
    {
        DrawerLayout drawerLayout;
        NavigationView navigationView;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_working);
        }

    }
}

toolbar.axml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"    
      xmlns:app="http://schemas.android.com/apk/res-auto"    
      android:id="@+id/main_content"    
      android:layout_width="match_parent"    
      android:layout_height="match_parent">

  <android.support.design.widget.AppBarLayout    
     android:id="@+id/appbar"    
     android:layout_width="match_parent"    
     android:layout_height="wrap_content"    
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">    

  <android.support.v7.widget.Toolbar    
     android:id="@+id/toolbar"    
     android:layout_width="match_parent"    
     android:layout_height="wrap_content"    
     android:elevation="4dp"    
     android:background="?attr/colorPrimary" />  

  </android.support.design.widget.AppBarLayout>    
</android.support.design.widget.CoordinatorLayout>  

nav_header.axml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
   xmlns:app="http://schemas.android.com/apk/res-auto"    
   android:layout_width="match_parent"    
   android:layout_height="210dp"    
   android:background="#0099ff"    
   android:padding="16dp"    
   android:orientation="vertical"    
   android:gravity="bottom">    
   <TextView    
      android:text="User Name"    
      android:layout_width="match_parent"    
      android:layout_height="wrap_content"    
      android:id="@+id/navheader_username"    
      android:textAppearance="@style/TextAppearance.AppCompat.Body1" />    
</LinearLayout>  

menu.xml:

<?xml version="1.0" encoding="utf-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

   <item android:id="@+id/nav_main"
    android:title="Home"></item>

   <item android:id="@+id/nav_message"
    android:title="Message"></item>

   <item android:id="@+id/nav_about"
    android:title="About"></item>

   <item android:id="@+id/nav_feedback"
    android:title="Feedback"></item>

</menu> 

styles.xml:

<resources>

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#2c3e50</color>
    <color name="colorPrimaryDark">#1B3147</color>
    <color name="colorAccent">#3498db</color>
</resources>

What can be problem?

Before I added files for navigation everything was fine.

Upvotes: 4

Views: 3876

Answers (3)

Moustafa Ahmed
Moustafa Ahmed

Reputation: 1

I've found the error in "android.suport.v7.widget.Toolbar" I wrote it suport instead of support make sure that you write it correctly

Upvotes: 0

Alexander Mujirishvili
Alexander Mujirishvili

Reputation: 365

I changed

android.support.v7.widget.DrawerLayout

to

android.support.v4.widget.DrawerLayout

and problem was solved.

Upvotes: 0

Leandro Keen Zapa
Leandro Keen Zapa

Reputation: 196

It might be due to dependency problem.

Try this. But first create a backup for your solution.

  1. Select the solution in Solution Explorer.
  2. Click Tools Menu > Nuget Package Manager > Manage Nuget Packages for Solution
  3. Find the item in "Installed": Xamarin Forms
  4. Look at the right pane then check all the projects of the solution, and click on the Uninstall button
  5. Restart Visual Studio
  6. Re-install Xamarin Forms
  7. Right-click the solution, and choose Clean Solution
  8. Recompile the application.

Hope this works.

Upvotes: 1

Related Questions