【问题标题】:how fix Error inflating class android.support.design.widget.NavigationView如何修复错误膨胀类 android.support.design.widget.NavigationView
【发布时间】:2020-02-06 03:00:40
【问题描述】:

我有问题,我找不到解决方案! 我在 XML 中使用:

<?xml version="1.0" encoding="utf-8"?>

    <androidx.drawerlayout.widget.DrawerLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/activity_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.example.libraryproject.MainActivity"
      android:background="@android:color/holo_green_dark">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Main"
            android:textSize="50dp"
            android:id="@+id/textView"
            android:layout_marginTop="200dp"
            android:layout_marginLeft="130dp"/>


    </RelativeLayout>

    <android.support.design.widget.NavigationView ------! #32
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:menu="@menu/navigation_menu"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_header"
        android:id="@+id/nv">
    </android.support.design.widget.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>

错误显示是: android.view.InflateException: Binary XML file line #32: Binary XML file line #32: Error inflating class android.support.design.widget.NavigationView

在应用程序中:

【问题讨论】:

标签: java android androidx android-navigationview material-components-android


【解决方案1】:

android.support.design.widget.NavigationView 替换为com.google.android.material.navigation.NavigationView,因为您使用的是AndroidX。

【讨论】:

    【解决方案2】:

    在您的build.gradle 中有一些错误

    • 支持库 29.0.2 和 29.1.1 不存在
    • 您正在同时使用 androidx 和支持库,而您不能这样做。

    那么,既然你使用的是androidx组件&lt;androidx.drawerlayout.widget.DrawerLayout你必须使用

    <com.google.android.material.navigation.NavigationView
     ...>
    

    而不是android.support.design.widget.NavigationView

    最后检查您的应用主题。您必须使用Material Component Theme

    【讨论】:

      猜你喜欢
      • 2019-07-05
      • 2016-11-12
      • 2016-05-30
      • 2016-08-16
      • 2017-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多