浮动动作按钮不适用于棉花糖和棒棒糖

时间:2018-03-15 03:59:32

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

我的应用中有FloatingActionButton。它在Android N和O中运行良好。但它在Marshmallow崩溃了。任何人都可以帮我解决这个问题。

错误

 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'
}

2 个答案:

答案 0 :(得分:2)

也许是因为你在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"

希望有所帮助

答案 1 :(得分:1)

  

这项工作在棉花糖和棒棒糖

  <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"/>
  

在App gradle文件中添加以下内容

    compileSdkVersion 26
    buildToolsVersion "26.0.2"

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