Floating action button with background
I tried to implement a floating action button in my other project using fab and set it up and it works fine. But this time when I create fab object in my xml layout it shows error. Feeling confused, he tried to remove part of his tag and found out that when passing android: backgroundTint the tag appears.
Here is the code:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_action_fab"
android:backgroundTint="#2196F3"
android:layout_margin="12dp"/>
Here is my build:
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.xxxx.xxxx"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "2.0.4"
}
I also added google gradle design.
Mistake:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxx.xxxx/com.xxxx.xxxx.HomeActivity}: android.view.InflateException: Binary XML file line #141: Binary XML file line #141: Error inflating class android.support.design.widget.FloatingActionButton
As soon as I remove the android: backgroundtint tag, the error is gone. Any idea why this is happening?
source to share
According to the documentation , it defaults to the color set in the styles.xml colorAccent attribute .
If you want to change color, in XML with attribute
and not app:backgroundTint
android:backgroundTint
So the final XML icon for fab would be
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_action_fab"
app:backgroundTint="#2196F3"
android:layout_margin="12dp"/>
source to share