如何解决错误膨胀类android.support.design.widget.BottomNavigationView?

zfciruhq  于 2023-05-21  发布在  Android
关注(0)|答案(2)|浏览(93)

我试图实现方法底部导航视图,但当我运行我的代码,我得到这个错误
引起:android.view.InflateException:二进制XML文件行#19:二进制XML文件行#19:扩展类android.support.design.widget.BottomNavigationView时出错android.view.InflateException:二进制XML文件行#19:扩展类android.support.design.widget.BottomNavigationView时出错java.lang.ClassNotFoundException:在以下路径中未找到类“android.support.design.widget.BottomNavigationView”:DexPathList[
这个问题怎么解决呢?
活动_主页布局

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    app:layout_behavior="android:.support.design.widget.BottomSheetBehaviour"
    tools:context=".HomeActivity">

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

    </FrameLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/purpleBae"
        app:itemIconTint="@android:color/white"
        app:itemTextColor="@android:color/white"
        app:menu="@menu/home_menu" />

</RelativeLayout>

build.gradle(模块应用程序)

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.gerobokgoapp"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        // Exclude file to avoid
        // Error: Duplicate files during packaging of APK
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

    compileOptions {
        incremental true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    //add libraries
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation 'com.google.firebase:firebase-firestore:21.0.0'
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
    implementation 'com.facebook.android:account-kit-sdk:4.39.0'

    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    testImplementation 'androidx.test.ext:junit:1.1.1'
}
w8ntj3qf

w8ntj3qf1#

你不能在同一个项目中混合使用support和androidx库,除非你使用Jetpack工具,否则肯定会有冲突。将支持库迁移到androidx
另外,Androidx布局文件中的引用都应该是androidx工件,而不是其他工件。
因此,标记如下:

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/purpleBae"
    app:itemIconTint="@android:color/white"
    app:itemTextColor="@android:color/white"
    app:menu="@menu/home_menu" />

应为:

<com.google.android.material.bottomnavigation.BottomNavigationView
  android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/purpleBae"
    app:itemIconTint="@android:color/white"
    app:itemTextColor="@android:color/white"
    app:menu="@menu/home_menu" />
cbeh67ev

cbeh67ev2#

添加以下依赖项:

dependencies {
    // https://mvnrepository.com/artifact/com.google.android.material/material
    implementation "com.google.android.material:material:1.0.0"
}

使用com.google.android.material.bottomnavigation.BottomNavigationView

相关问题