浮动操作按钮在棉花糖和棒棒糖中不起作用

Floating action button not working in marshmallow and lollipop

我的应用程序中有 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" />

build.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"

希望对您有所帮助

This work in marshmallow and lollipop

  <android.support.design.widget.FloatingActionButton
            android:id="@+id/floatingButtonCustomer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:visibility="visible"
            android:src="@drawable/refresh"
            android:layout_above="@+id/floatingButtonAdd"
            android:layout_alignLeft="@+id/floatingButtonAdd"
            android:layout_marginBottom="10dp"/>

Add bellow in App gradle file

    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    compile 'com.android.support:design:26.1.0'
    compile 'com.android.support:support-v13:26.1.0'