InflateException with FloatingActionButton from Official Design Library

前端 未结 7 1527
谎友^
谎友^ 2020-11-27 04:54

I am getting a bug using the official FloatingActionButton from Google\'s support design library.

Here is my LogCat.

android.view.Infla         


        
相关标签:
7条回答
  • 2020-11-27 05:05

    I had the same issue and tried different solution. But the one that worked for me was to ensure that appcompat and design support library versions are the same. for example:

    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'
    
    0 讨论(0)
  • 2020-11-27 05:08

    Another way to get this message is if you accidentally specified different versions of the appcompat library in different modules. This is likely to happen when you create a new module, since Android Studio defaults to the most current version.

    For a tidy way of managing this in multi-module projects, see: In Gradle, how do I declare common dependencies in a single place?

    0 讨论(0)
  • 2020-11-27 05:09

    in my case, it was because of the false configuration of activity theme. problem was solved after i changed app theme to Theme.AppCompat.xxx.

    0 讨论(0)
  • 2020-11-27 05:14

    com.android.support:appcompat-v7:21+ added support for tinting widgets on devices running pre android 5.1 (API Level 21). To make use of it make sure you extend or set the AppCompat Theme and use app:backgroundTint instead of android:backgroundTint.

    Example:

    <android.support.design.widget.FloatingActionButton 
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:src="@drawable/icon"
        app:backgroundTint="@color/accent"
        app:borderWidth="0dp" />
    
    0 讨论(0)
  • 2020-11-27 05:18

    Just change android to app:

    android:backgroundTint="@color/accent"
    

    To:

    app:backgroundTint="@color/accent"
    
    0 讨论(0)
  • 2020-11-27 05:19

    If you're using a VectorDrawableCompat (Vector asset) you should use:

    app:srcCompat="@drawable/x"
    

    instead of:

    android:src="@drawable/x"
    
    0 讨论(0)
提交回复
热议问题