【问题标题】:Unhandled Exception: Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1未处理的异常:Android.Views.InflateException:二进制 XML 文件第 1 行:二进制 XML 文件第 1 行
【发布时间】:2018-04-18 15:10:24
【问题描述】:

在 Xamarin Android 中,当我从 Activity 调用 axml 文件时,出现以下错误,

“未处理的异常:

Android.Views.InflateException:二进制 XML 文件第 1 行:二进制 XML 文件第 1 行:膨胀类错误 android.support.design.widget.BottomNavigationView 发生”

我在这里停留了 2 天,我没有得到错误的原因。请帮帮我。

我在这一行遇到错误,

SetContentView(Resource.Layout.main_page);

我的 axml 文件是,

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

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_navigation" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_alignParentBottom="true"
        android:background="@android:color/white"
        app:elevation="16dp"
        app:menu="@menu/bottom_navigation_main"/>
</RelativeLayout>

提前致谢。

【问题讨论】:

  • 确保您在项目中配置了 com.android.support:design 库。
  • 是的..它已配置
  • 试试这个 从 gradle 中删除 com.android.support:design。清理项目再次添加com.android.support:design并重新同步。
  • 我试过了..我遇到了同样的问题..
  • 你能发布你的应用 build.gradle 吗?

标签: android xamarin xamarin.android


【解决方案1】:

您能否发布您正在使用的活动的代码 这段代码:SetContentView(Resource.Layout.main_page);

您是否在活动中找到了您的 BottomNavigationView 的引用 通过编写 BottomNavigationView bottomView=
FindViewById(Resource.id.hereYourIdOfBottomNavigationView);

如果您没有找到,请尝试查找并运行您的代码。

【讨论】:

  • 这应该在问题的评论部分而不是答案部分。
  • 我无法发表评论,这就是我将其写在答案部分的原因。对于发表评论,我们至少有 50 点声望点,而我没有那么多声望点。
【解决方案2】:

您的 activity 应该继承自 AppCompatActivity
并确保您的Xamarin.Android.Support.DesignXamarin.Android.Support.v7.AppCompat 版本相同。

【讨论】:

    猜你喜欢
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多