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

后端 未结 12 1715
清歌不尽
清歌不尽 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:44

    Below API level 21 app versions not support for the

    app:backgroundTint="@color/green"
    

    or you can use this library for achieve more material design widgets.

    https://github.com/navasmdc/MaterialDesignLibrary

    happy coding...

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

    I was using Material Design for my ExtendedFloatingActionButton and when using API 24 it would crash the app.

    I tried updating my gradle dependencies to the latest version:

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0-alpha02'
    

    but I had no luck with that either. My solution was adding android:theme="" even though I had set a style it would still crash so I set the theme to the same as the style and it worked perfectly.

    <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
                        android:id="@+id/btn_one"
                        android:theme="@style/"
                        style="@style/"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/text"
                        android:text="@string/text"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
    
    0 讨论(0)
  • 2021-02-05 01:46

    You need to add

    android:theme="@style/Theme.AppCompat"

    in the XML_Layout file in which you are using FloatingActionButton...

    0 讨论(0)
  • 2021-02-05 01:50
     <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end|bottom"
            android:src="@drawable/ic_add_foreground"
            android:layout_margin="16dp" />
    

    Use this

     <com.google.android.material.floatingactionbutton.FloatingActionButton>
    

    instead of

    <android.support.design.widget.FloatingActionButton>
    
    0 讨论(0)
  • 2021-02-05 01:50

    Add in

    build.gradle(:app)

     implementation 'com.google.android.material:material:1.2.0'
    

    Use this in your XML

    <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_margin="16dp"
            android:src="@drawable/icon_right"
            app:backgroundTint="@color/green"
            android:onClick="previewphoto"
            app:layout_anchorGravity="bottom|right|end" />
    
    0 讨论(0)
  • Use

    app:backgroundTint
    

    in stead of

    android:backgroundTint
    

    Hope it will work.

    0 讨论(0)
提交回复
热议问题