My app crashed because
Error inflating class android.support.design.widget.FloatingActionButton
This is my code in the XML
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...
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" />
You need to add
android:theme="@style/Theme.AppCompat"
in the XML_Layout file in which you are using FloatingActionButton...
<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>
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" />
Use
app:backgroundTint
in stead of
android:backgroundTint
Hope it will work.