Android.Views.InflateException:二进制XML文件第1行:二进制XML文件第1行:错误膨胀了类android.support.design.widget.NavigationView

时间:2018-08-30 14:15:58

标签: android xamarin xamarin.android

我是android应用程序开发的新手,并且出现以下错误:

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

我有一个活动-WorkingActivity.cs,看起来像这样:

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

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

        //getting error here
        SetContentView(Resource.Layout.activity_working);

    }

}

对应的布局文件-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.v4.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.v4.widget.DrawerLayout>   
</LinearLayout>

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="100dp"    
  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>  

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>

styles.xml:

<resources>


<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
  <item name="android:textColorPrimary">#212121</item>
  <item name="android:textColorSecondary">#727272</item>
  <item name="windowActionBar">false</item>
  <item name="windowNoTitle">true</item>
</style>

</resources>

这些是我的项目的引用:

enter image description here

当我在同一文件夹中添加(仅添加,仅添加其他内容)名为activity_new_visit.axml(名称无关紧要)的新布局文件时出现此错误:

  

activity_new_visit.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">
</LinearLayout>    

原因是什么?

编辑:

我在github上上传了项目:https://github.com/AlexDev5/App2

1 个答案:

答案 0 :(得分:1)

我在forums.xamarin.com上找到了解决方案:

enter image description here