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=”https://stackoverflow.com/questions/30870443/@drawable/icon” app:backgroundTint=”@color/accent” app:borderWidth=”0dp” />

FloatingActionButton with text instead of image

Thanks to all. Here is easy workaround which I found for this question. Works correctly for Android 4+, for Android 5+ is added specific parameter android:elevation to draw TextView over FloatingActionButton. <FrameLayout android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”bottom|right”> <android.support.design.widget.FloatingActionButton android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:src=”https://stackoverflow.com/questions/33671196/@android:color/transparent” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”center” android:text=”@android:string/ok” android:elevation=”16dp” android:textColor=”@android:color/white” android:textAppearance=”?android:attr/textAppearanceMedium” /> </FrameLayout>

Android Design Library – Floating Action Button Padding/Margin Issues

Update (Oct 2016): The correct solution now is to put app:useCompatPadding=”true” into your FloatingActionButton. This will make the padding consistent between different API versions. However, this still seems to make the default margins off by a little bit, so you may need to adjust those. But at least there’s no further need for API-specific styles. … Read more

FloatingActionButton example with Support Library

So in your build.gradle file, add this: compile ‘com.android.support:design:27.1.1′ AndroidX Note: Google is introducing new AndroidX extension libraries to replace the older Support Libraries. To use AndroidX, first make sure you’ve updated your gradle.properties file, edited build.gradle to set compileSdkVersion to 28 (or higher), and use the following line instead of the previous compile one. … Read more

Set FAB icon color

UPDATE 2 If you are using com.google.android.material.floatingactionbutton.FloatingActionButton, use app:tint app:tint=”@android:color/white” UPDATE Refer to the answer of @Saleem Khan which is the standard way to set the app:tint using: android:tint=”@android:color/white” via XML on FloatingActionButton. OLD (June 2015) This answer was written before October 2015, when android:tint on FloatingActionButton was supported only with API >= 21. You … Read more

Android Design Support Library expandable Floating Action Button(FAB) menu

Got a better approach to implement the animating FAB menu without using any library or to write huge xml code for animations. hope this will help in future for someone who needs a simple way to implement this. Just using animate().translationY() function, you can animate any view up or down just I did in my … Read more

How can I add the new “Floating Action Button” between two widgets/layouts

Best practice: Add compile ‘com.android.support:design:25.0.1’ to gradle file Use CoordinatorLayout as root view. Add layout_anchorto the FAB and set it to the top view Add layout_anchorGravity to the FAB and set it to: bottom|right|end <android.support.design.widget.CoordinatorLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:layout_width=”match_parent” android:layout_height=”match_parent”> <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical”> <LinearLayout android:id=”@+id/viewA” android:layout_width=”match_parent” android:layout_height=”match_parent” android:layout_weight=”0.6″ android:background=”@android:color/holo_purple” android:orientation=”horizontal”/> <LinearLayout android:id=”@+id/viewB” android:layout_width=”match_parent” android:layout_height=”match_parent” android:layout_weight=”0.4″ … Read more

Android changing Floating Action Button color

As described in the documentation, by default it takes the color set in styles.xml attribute colorAccent. The background color of this view defaults to the your theme’s colorAccent. If you wish to change this at runtime then you can do so via setBackgroundTintList(ColorStateList). If you wish to change the color in XML with attribute app:backgroundTint … Read more