Error inflating class android.support.design.widget.FloatingActionButton

后端 未结 12 1714
清歌不尽
清歌不尽 2021-02-05 01:24

My app crashed because

Error inflating class android.support.design.widget.FloatingActionButton

This is my code in the XML



        
相关标签:
12条回答
  • 2021-02-05 01:26

    I am using:

    classpath 'com.android.tools.build:gradle:3.3.2'

    and

    distributionUrl=https://services.gradle.org/distributions/gradle-4.10.1-all.zip

    I changed my XML to:

    <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:clickable="true"
            android:focusable="true"
            app:srcCompat="@drawable/mapit"
            app:layout_anchor="@id/foundit_imageView"
            app:layout_anchorGravity="bottom|right|end" />
    

    and everything built and ran correctly.

    I hope this helps

    0 讨论(0)
  • 2021-02-05 01:34

    Because android:backgroundTint doesn't work below android API 21, so you need to use app:backgroundTint instead.

    0 讨论(0)
  • 2021-02-05 01:39

    use this code it will be work better ;

    <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_margin="16dp"
            app:backgroundTint="#f9fcfc"
    
            android:src="@drawable/chat_float"
            tools:targetApi="lollipop" />
    
    0 讨论(0)
  • 2021-02-05 01:40

    Tried your code, the problem is with the 23.4.0 library.

    Upgrade to 24.+ , there's no error in that lib.

    For example :

    implementation 'com.android.support:appcompat-v7:24.2.1' // appcompat library
    implementation 'com.android.support:design:24.2.1'
    

    You need to change the compile version to 24 too.

    compileSdkVersion 24
    
    0 讨论(0)
  • 2021-02-05 01:41

    Make sure the library from which you declared the FloatingActionButton in the activity is the same as the one used for the layout markup

    For example have

    import com.google.android.material.floatingactionbutton.FloatingActionButton; in the activity and com.google.android.material.floatingactionbutton.FloatingActionButton as the tag for the layout

    0 讨论(0)
  • 2021-02-05 01:42

    I had the same problem

    I faced the same issue with Pre-Lolipop version and to resolve it, I just changed "android:src" to "app:srcCompat" & it worked for me.

    To make compatibility with older version and if you're using a Vector graphics (as drawable assets) you should use:

    app:srcCompat="@drawable/you_graphics"
    

    instead of:

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