gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:55:01 25 4
gpt4 key购买 nike

我是 Android 应用程序开发的新手,我正在尝试向我的应用程序添加导航,但我在 WorkingActivity 中的 SetContentView(Resource.Layout.activity_working); 上收到此错误。 CS:

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

这些是我的文件:

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>

菜单.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>

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

有什么问题?

在我添加导航文件之前,一切都很好。

最佳答案

可能是依赖问题。

试试这个。但首先要为您的解决方案创建一个备份。

  1. 在解决方案资源管理器中选择解决方案。
  2. 单击工具菜单 > Nuget 包管理器 > 管理解决方案的 Nuget 包
  3. 在“已安装”中找到项目:Xamarin Forms
  4. 查看右侧 Pane ,然后检查解决方案的所有项目,然后单击“卸载”按钮
  5. 重新启动 Visual Studio
  6. 重新安装 Xamarin Forms
  7. 右键单击解决方案,然后选择“清理解决方案”
  8. 重新编译应用程序。

希望这能奏效。

关于c# - Android.Views.InflateException : Binary XML file line #1: Binary XML file line #1: Error inflating class android. support.v7.widget.DrawerLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52092638/

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