android - 无法充气并且没有找到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"
解决方案
您正在使用新的 Android Material Components for Android作为依赖项,而不是“旧的” Android Design Support Library。android.support.design.widget.BottomSheetBehavior
但是,您正在引用不再存在的旧库中的字符串。因此,为了使其正常工作,只需更改app:layout_behavior
from
android.support.design.widget.BottomSheetBehavior
至
com.google.android.material.bottomsheet.BottomSheetBehavior
推荐阅读
- amazon-web-services - AWS Cognito 确认后
- gcc - 内部编译器错误:尝试编译 sqlite3.c 时 gcc 中的非法指令
- objective-c - 打印在自动释放池中设置的 NSString 的值
- r - 为 linux (Ubuntu for Windows) 安装 biomaRt 包 (R 版本 3.5.2)
- html - 我将宽度 pf 搜索框设置为 0。但它仍然显示它。可能是因为我使用的是 flex。但为什么?
- vim - 在 .vimrc 映射中使用寄存器
- apache-spark - 使用 SQL 更新 Spark 表中的列
- javascript - 动态更改vue js中的公共路径
- android - 如何使用 ViewModel(MVVM) 将对象从片段传递到活动详细信息视图?
- sql - 在不同条件下两次加入同一张表