android - float 操作按钮在棉花糖和 Lollipop 中不起作用

标签 android android-6.0-marshmallow floating-action-button

我的应用程序中有FloatingActionButton。它在 Android N 和 O 中运行良好。但它在棉花糖中崩溃了。谁能帮我解决这个问题。

错误

 Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.FloatingActionButton
   at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
   at LibraryFragment.onCreateView(LibraryFragment.java:69)

XML

 <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabChat"
        android:backgroundTint="#114358"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="100dp"
        android:layout_marginRight="16dp"
        app:srcCompat="@drawable/language"
        app:borderWidth="0dp"
        app:elevation="4sp" />

构建.gradle

 compileSdkVersion 26
        defaultConfig {

            minSdkVersion 15
            targetSdkVersion 26

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.github.moondroid.coverflow:library:1.0'

    compile 'com.google.android.gms:play-services-ads:11.8.0'
    compile 'com.android.support:recyclerview-v7:26.1.0'
    compile 'com.android.support:cardview-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.github.florent37:diagonallayout:1.0.2'
    compile 'de.hdodenhof:circleimageview:2.1.0'
}

最佳答案

可能是因为您使用的 Android 设计库版本不同:

将其粘贴到依赖项中,如果它已经存在,则替换它

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'

同时将compileSdkVersion更改为25

同时更改: android:backgroundTint="#114358"app:backgroundTint="#114358"

如果您使用矢量资源作为 src,则使用

app:srcCompat="@drawable/you_graphics"

安装了这个 android:src="@drawable/your_graphics"

希望对你有帮助

关于android - float 操作按钮在棉花糖和 Lollipop 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49291349/

相关文章:

java - 使用 com.github.clans.fab.FloatingActionButton 时命名空间 'fab' 未绑定(bind)错误

android - 如何从opencv android中的选定轮廓裁剪图像

android - 在 Marshmallow 设备中加载 map 时获取 android.view.InflateException

android-layout - PopupMenu 子菜单不遵守重力对齐

android - 当 snackbar 在android中显示消息时, float 操作按钮不会上升

android - 当 RecyclerView 位于 SwipeRefreshLayout 内时,如何使用 Behavior 滚动 RecyclerView 时显示/隐藏 FloatingActionButton?

android - 如何以编程方式减少操作栏选项卡的宽度

Android 模拟器(API 级别 8)- 介绍 ANDROID 消息后只是黑屏

android - 随机 Espresso 测试失败

Android Marshmallow, "dangerous"保护级别和系统组件/应用程序