Search code examples
androidandroid-layoutfloating-action-button

Below API level 24 => Error inflating class android.support.design.widget.FloatingActionButton


I am getting this exception when I am running my code below API level 24.

FATAL EXCEPTION: main Process: com.example.scanwithanimations, PID: 13393 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.scanwithanimations/com.example.scanwithanimations.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class

android.support.design.widget.FloatingActionButton

My main.xml is as follows.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingTop="16dp">

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="164dp"
    android:src="@drawable/ic_action_wifi"
    android:elevation="6dp"
    android:id="@+id/fabwifi"
    app:pressedTranslationZ="12dp"
    android:backgroundTint="@color/fab1"
    android:visibility="invisible"
    />

</android.support.design.widget.CoordinatorLayout>

Solution

  • use this

    • app:elevation="6dp"
    • app:backgroundTint="@color/fab1"

    insted of this

    • android:elevation="6dp"
    • android:backgroundTint="@color/fab2"

    sample code

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="164dp"
        android:src="@drawable/ic_action_wifi"
        app:elevation="6dp"
        android:id="@+id/fabwifi"
        app:pressedTranslationZ="12dp"
        app:backgroundTint="@color/fab1"
        android:visibility="invisible"
        />