1

I have noticed that the app only crashes when I have a backgroundTint on the fab in my main activity.

Here is a screenshot of the error:

Screenshot

here is my main activity:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:backgroundTint="@color/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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

<include layout="@layout/content_main"
    android:id="@+id/include" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:backgroundTint="@color/colorPrimary"
    android:tint="@color/colorWhite"
    app:fabSize="normal"
    app:srcCompat="@android:drawable/ic_input_add"/>

and here is the crash log:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: xyz.gregswebsite.notes, PID: 19184
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{xyz.gregswebsite.notes/xyz.gregswebsite.notes.MainActivity}: android.view.InflateException: Binary XML file line #27: Binary XML file line #27: Error inflating class android.support.design.widget.FloatingActionButton
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
                      at android.app.ActivityThread.access$900(ActivityThread.java:157)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5551)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
                   Caused by: android.view.InflateException: Binary XML file line #27: Binary XML file line #27: Error inflating class android.support.design.widget.FloatingActionButton
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:539)

and here is a picture of my build.gradle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 24
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "xyz.gregswebsite.notes"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',  {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    testCompile 'junit:junit:4.12'
}
Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
GJ COD
  • 9
  • 3

3 Answers3

1

Ok, based on the answer here, you may need to change the android:backgroundTint to app:backgroundTint. The theme also needs to be AppCompat. It should be working on 22 up, but see if that works.

Community
  • 1
  • 1
jaywhy13
  • 1,068
  • 12
  • 16
0

You should to replace android:tint="@color/colorWhite" to app:backgroundTint="@color/accent" One

Surya Prakash Kushawah
  • 3,185
  • 1
  • 22
  • 42
0

The answer from Markus on this post seems to solve your issue.

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" />
Community
  • 1
  • 1
Ashhar Jawaid
  • 132
  • 1
  • 8