Search code examples
androidxmlfloating-action-buttonandroid-vectordrawable

error with fab button design with vector assets


I have used the dependencies to be used as suggested. below is the pic. build_gradle(module)

now I have selected a black plus icon from vector assets and named it as fab_plus, now I have this file in my drawable folder. fab_plus_XML now I tried to used that fab_plus_XML like this. Pic below. activity_main

Now my question is why is the fab_plus is showing in red.

thanks in advance. pls, help me, someone.


Solution

  • There are two things wrong with the way you are specifying the drawable. To refer to a drawable within your project, you simply use @drawable/your_drawable and to allow backward compatibility of VectorDrawables you should use app:srcCompat as per the guidance.

    So in your ImageView, instead of

    android:src="@android:drawable/fab_plus"
    

    you should have

    app:srcCompat="@drawable/fab_plus"
    

    You will also need to make sure the app namespace is included at the top of your layout xmlns:app="http://schemas.android.com/apk/res-auto" along with the current android and tools namespaces.