Inflateexception with Floatingactionbutton from Official Design Library

InflateException with FloatingActionButton from Official Design Library

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

Android Studio: Error inflating class android.support.design.widget.FloatingActionButton

For any person still having this problem after febuary 2019, if you are using androidx or the new material libraries, This problem is happening because Google changed the naming format of the libraries using androidx.. you can check this official mapping https://developer.android.com/jetpack/androidx/migrate/artifact-mappings
and search for your library to see what the new name is, now that Google is in androidx

In your case, your library "android.support.design.widget.FloatingActionButton" in your xml file, is now called as using com.google.android.material.floatingactionbutton.FloatingActionButton

android.support.design.button.MaterialButton throws InflateException

Ensure that the App Theme style is inherited from Theme.MaterialComponents

Example:

<style name="XXXXXAppTheme" parent="@style/Theme.MaterialComponents.Light.DarkActionBar"> 

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

Please change it into AppCompatActivity if you use Activity. Probably it becomes the error when it is Activity.



Related Topics



Leave a reply



Submit