Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Floating action button not showing vector asset

Posted on November 11, 2022 By

Solution 1 :

Set

android {
   defaultConfig {
     vectorDrawables.useSupportLibrary = true
    }
 }

in your build.gradle

Solution 2 :

I think you need to update your dependencies

I got it to work while using those dependencies:

implementation 'androidx.appcompat:appcompat:1.2.0-alpha02'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "com.google.android.material:material:1.1.0"


<com.google.android.material.floatingactionbutton.FloatingActionButton
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_src="@drawable/drawable_test"
    />

Screen shot

Solution 3 :

I know it’s old question, and others might have the same problem, so I add this answer.

As others suggested, add the following dependencies to build.gradle:

implementation 'androidx.appcompat:appcompat'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'

Also as others suggested, add this to build.gradle:

android {
   defaultConfig {
     vectorDrawables.useSupportLibrary = true
    }
 }

In the vector, change android:width and android:height to android:width="24dp" and android:height="24dp".

In layout, in com.google.android.material.floatingactionbutton.FloatingActionButton, add app:fabCustomSize="56dp" or instead of this, add app:fabSize="normal".

Solution 4 :

The FloatingActionButton widget provides a complete implementation of Material Design’s floating action button component.

upgrade your dependencies

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

Using AppCompat and app:srcCompat is the most foolproof method of
integrating vector drawables into your app.

Finally

 <com.google.android.material.floatingactionbutton.FloatingActionButton
      app_srcCompat="@drawable/your_vector"

Note – Kindly reduce width,height value.

   <vector xmlns_android="http://schemas.android.com/apk/res/android"
    android_width="20dp"
    android_height="20dp"
    android_viewportWidth="200"
    android_viewportHeight="200">

Android Studio 1.4 introduced limited compatibility support for vector
drawables by generating PNG files at build time. However, the vector
drawable and animated vector drawable support Libraries offer both
flexibility and broad compatibility — it’s a support library, so you
can use it with all Android platform versions back to Android 2.1 (API
level 7+). To configure your app to use vector support libraries, add
the vectorDrawables element to your build.gradle file in the app
module.

Use the following code snippet to configure the vectorDrawables element:

//For Gradle Plugin 2.0+
 android {
   defaultConfig {
     vectorDrawables.useSupportLibrary = true
    }
 }

Solution 5 :

u can solve your issue with this idea,

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android_id="@+id/fab_new_sale"
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_layout_margin="16dp"
    android_layout_marginEnd="16dp"
    android_layout_marginBottom="16dp"
    app_backgroundTint="@color/colorAccent"
    app_layout_constraintBottom_toBottomOf="parent"
    app_layout_constraintEnd_toEndOf="parent"
    android_src="@drawable/ic_cart_plus"
    android_scaleType="center"/>

here u can use android:src insted of app:srcCompat

READ  [FIXED] android - Changing fragment get IllegalStateException must not be null in kotlin
Powered by Inline Related Posts

Solution 6 :

It worked for me using the following depencencies

implementation 'androidx.appcompat:appcompat'
implementation 'com.google.android.material:material:1.1.0'
implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4"

try updating these depencencies. I didnt have to do any rescaling. maybe also refer to this and this questions as it might be that your drawable is just not centered properly and leaving the circle

Solution 7 :

You just need to change your srcCompat to src, and that would solve the problem for you.
I am attaching my own FAB code for your ease:

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android_id="@+id/fab_explore"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_margin="@dimen/dp_16"
        android_src="@drawable/ic_explore_black_24dp"
        app_backgroundTint="@color/accent"
        app_tint="@color/color_white"
        app_layout_constraintEnd_toEndOf="parent"
        app_layout_constraintBottom_toBottomOf="parent" />

Problem :

I’m trying to setup a vector asset into a fab. But the result is like this:
enter image description here
As you can see the vector is there but way down and to the left. here is the layout

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    android_background="@color/colorBg"
    tools_context=".ui.main.fragments.HomeFragment">


    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android_id="@+id/fab_new_sale"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_margin="16dp"
        android_layout_marginEnd="16dp"
        android_layout_marginBottom="16dp"
        app_backgroundTint="@color/colorAccent"
        app_layout_constraintBottom_toBottomOf="parent"
        app_layout_constraintEnd_toEndOf="parent"
        app_srcCompat="@drawable/ic_cart_plus"
        android_scaleType="center"/>

    <androidx.recyclerview.widget.RecyclerView
        android_id="@+id/rv_home_cards"
        android_layout_width="0dp"
        android_layout_height="0dp"
        android_foregroundGravity="center_vertical|center"
        app_layout_constraintBottom_toBottomOf="parent"
        app_layout_constraintEnd_toEndOf="parent"
        app_layout_constraintStart_toStartOf="parent"
        app_layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

And heres is the vector:

<vector xmlns_android="http://schemas.android.com/apk/res/android"
    android_width="200dp"
    android_height="200dp"
    android_viewportWidth="200"
    android_viewportHeight="200">
    <path
        android_fillColor="#FF000000"
        android_pathData="M165.1,119.28L75,119.28l2,9.84h82.48a7.37,7.37 0,0 1,7.19 9l-1.7,7.46a17.2,17.2 0,1 1,-19.54 3.19L81,148.77a17.21,17.21 0,1 1,-20.6 -2.63L38.85,40.62L17.38,40.62A7.38,7.38 0,0 1,10 33.24L10,28.33A7.37,7.37 0,0 1,17.38 21h31.5a7.38,7.38 0,0 1,7.23 5.9l2.81,13.77h120.7a7.37,7.37 0,0 1,7.19 9l-14.52,63.91A7.38,7.38 0,0 1,165.1 119.28ZM135.38,72.58L120.63,72.58L120.63,60.28a4.92,4.92 0,0 0,-4.92 -4.91h-4.92a4.91,4.91 0,0 0,-4.91 4.91v12.3L91.13,72.58a4.91,4.91 0,0 0,-4.92 4.91v4.92a4.92,4.92 0,0 0,4.92 4.92h14.75L105.88,99.62a4.91,4.91 0,0 0,4.91 4.91h4.92a4.92,4.92 0,0 0,4.92 -4.91L120.63,87.33h14.75a4.92,4.92 0,0 0,4.91 -4.92L140.29,77.49A4.91,4.91 0,0 0,135.38 72.58Z" />
</vector>

I will appreciate any help with this issue

Comments

Comment posted by Md Golam Rahman Tushar

share your vector drawable xml!

Comment posted by Nice umang

Try android_src=”@drawable/ic_cart_plus” instead of app_srcCompat=”@drawable/ic_cart_plus”

Comment posted by fivunlm

Added vector drawable. Using src instead of srcCompat made no change

READ  [FIXED] android - Using same observer in multiple fragments and receiving the response only in the visible fragment not the one in backstack
Powered by Inline Related Posts

Comment posted by tynn

Could you try setting

Comment posted by Kasım Özdemir

If the problem is still keeping add this to build.gradle android { defaultConfig { vectorDrawables.useSupportLibrary = true } }

Android Tags:android, floating-action-button

Post navigation

Previous Post: [FIXED] java – How to solve debug issue
Next Post: [FIXED] android – How to solve setting up this payment problem – paypal

Related Posts

[FIXED] Android: Why does it create and activity, then destory it, then create again, at one time Android
[FIXED] Android studio shows “MainActivity.java uses or overrides a deprecated API.” but it also shows “Inspection of the code found nothing to report.” Android
[FIXED] android – 2D image is rendering on a vertical plane, horizontally. Why? Android
[FIXED] How to send hard coded string from Android APP when button is pressed to a UDP listener in Node-Red? Android
[FIXED] android – ClipDrawable width does not fit its parent Android
[FIXED] java – Google in app purchase version 5 purchase verification issue Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What are the main features of Islamic education?
  • Is the Jeep 4xe worth it?
  • How does the ringer work on cast iron?
  • What is the biggest size interior door?
  • Is blue raspberry an original Jolly Rancher flavor?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme