首页 > 解决方案 > 无法充气并且没有找到android支持设计BottomSheetBehavior的类行为

问题描述

我正在尝试在我的主要项目中实现底部模式表。我在一个演示项目中成功地做到了。但是当我将相同的结构应用于我的主项目时,应用程序崩溃并出现以下错误:

android.view.InflateException:二进制 XML 文件第 40 行:无法膨胀行为子类 android.support.design.widget.BottomSheetBehavior 原因:java.lang.RuntimeException:无法膨胀行为子类 android.support.design.widget.BottomSheetBehavior

AndroidRuntime:原因:java.lang.ClassNotFoundException:在路径上找不到类“android.support.design.widget.BottomSheetBehavior”:DexPathList [[zip文件“/data/app/com.example...... ..]]

我尝试了之前app:layout_behavior="@string/bottom_sheet_behavior"在我的 xml 中声明的方法,但它没有用。

在演示项目中,底部工作表在嵌套父视图中正常工作。

我的主要项目依赖项是 - (添加到 app build.gradle)

    def lifecycle_version = "2.1.0-alpha02"
    def room_version = "2.1.0-alpha04"
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    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.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'me.relex:circleindicator:2.1.0'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.github.chrisbanes:PhotoView:2.3.0'

    // ViewModel and LiveData
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
    implementation "androidx.room:room-runtime:$room_version"
    annotationProcessor "androidx.room:room-compiler:$room_version"

标签: androidandroid-design-librarybottom-sheetandroiddesignsupport

解决方案


您正在使用新的 Android Material Components for Android作为依赖项,而不是“旧的” Android Design Support Libraryandroid.support.design.widget.BottomSheetBehavior但是,您正在引用不再存在的旧库中的字符串。因此,为了使其正常工作,只需更改app:layout_behaviorfrom

android.support.design.widget.BottomSheetBehavior

com.google.android.material.bottomsheet.BottomSheetBehavior

推荐阅读