gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 13:47:10 26 4
gpt4 key购买 nike

我是 android 应用程序开发的新手,我遇到以下错误:

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

我有一个 Activity - 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>

样式.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

最佳答案

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

enter image description here

关于Android.Views.InflateException : Binary XML file line #1: Binary XML file line #1: Error inflating class android. 支持.design.widget.NavigationView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52099249/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com