Android:id 在 DrawerLayout 内容 View 中抛出错误

标签 android xamarin

我正在尝试将 TextView 放置在带有左侧抽屉的主要 Activity 中。可以毫无问题地放置 Textview,但是当我在 Textview 中添加 Android:id 时,它会抛出错误:

Android.Views.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class android.support.design.internal.NavigationMenuItemView.

此代码:有效

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/drawer_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  tools:openDrawer="start">

  <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        tools:showIn="@layout/app_bar_main"
        android:text="Hello World!" />

  <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

但是这段代码没有

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/drawer_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  tools:openDrawer="start">

  <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        tools:showIn="@layout/app_bar_main"
        android:id="@+id/textView1"
        android:text="Hello World!" />

  <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

我只添加了一行代码

android:id="@+id/textView1"

最佳答案

当您的 appcompat 库和设计支持库的版本不匹配时,可能会出现此问题。

 compile 'com.android.support:appcompat-v7:23.1.1' // appcompat library
 compile 'com.android.support:design:23.1.1'       //design support library

关于Android:id 在 DrawerLayout 内容 View 中抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53359584/

相关文章:

android - iOS Storyboard 有没有像 Android 一样的布局资源文件?

android - 错误:(246,5)错误:使用配置 'attr/rippleColor'复制资源 ''的值

android - Xamarin.Android.D8.Target - "java.exe"在创建混淆器配置文件时以代码 1 退出

c# - 如何在c#中关闭xmldocument

xamarin - 是否可以逐步调试由 NUnit 驱动的 Xamarin.UITest 下运行的 Xamarin 代码?

android - 海拔在 BottomNavigationView 上不起作用

php - 从 Web 应用程序向 Android 发送数据/文本

android - 从我的 contentProvider 获取最后一行

xamarin - VS2017 - Payload 包含两个或多个具有相同目标路径的文件

xamarin - 从 Visual Studio 2017 15.5.1 开始,如何创建 Xamarin.Forms 项目以使用 PCL 来定位最低 Android KitKat (API 19)?