I have a problem using srcCompat in the following code
<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:background="@android:color/white"
app:srcCompat="@drawable/ic_shopping_cart_black_24dp" />
the code with problems is
app:srcCompat="@drawable/ic_shopping_cart_black_24dp"
The error I have is:
To use VectorDrawableCompat, you need to set 'android.defaultConfig.vectorDrawables.useSupportLibrary = true'.
The beginning of the xml
<?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"
also in the build.gradle I have it activated
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
vectorDrawables.useSupportLibrary = true
Try adding this to your floating button:
If it doesn't work, after adding
vectorDrawables.useSupportLibrary = true
in your gradle, now in the class or classes that you refer to your button add:You need to add this to every activity you want to use
VectorDrawables
on devices below Android 5.I see that you have configured the support to use vector graphics, also if you use
compileSdkVersion 26
, you must have a version of AS 2.0+.Seems more like a cache issue to me, since enabling vector graphics support can be done within the
build.gradle
. this to support the use of these graphics in all operating systems.