Wrapper
Wrapper

Reputation: 932

Floating Action Button is not showing an image in Android?

As title says, I don't know how to fix this issue. I read this problem but that was in 2018, I'm not very familiar with all those libraries and dependencies how it all works. But judging from my Declared Dependencies, from Android Studio, this is what I got:

enter image description here

I would like to add some kind of "Attach document" icon/image to the FAB. I tried to do this by adding a New Vector asset, but images do not appear in my drawable folder. How can I add a nice icon/image to my project, and set it to a FAB?

Here is XML:

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:icon="@drawable/attache_file">

    </com.google.android.material.floatingactionbutton.FloatingActionButton>

Upvotes: 3

Views: 2958

Answers (3)

Abdul Rizwan
Abdul Rizwan

Reputation: 4108

I found the solution, just add this below statement inside dimens.xml

<dimen name="design_fab_image_size" tools:override="true">56dp</dimen>

And must need to add app:tint="@null" inside your FAB design xml

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/bottomBar"
        app:srcCompat="@drawable/ic_logo"
        app:tint="@null" />```

Happy to help :) 

Upvotes: 5

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364868

To use the com.google.android.material.floatingactionbutton.FloatingActionButton add the Material Components library:

implementation 'com.google.android.material:material:1.1.0'

Then use the app:srcCompat attribute:

  <com.google.android.material.floatingactionbutton.FloatingActionButton
      style="@style/Widget.MaterialComponents.FloatingActionButton"
      app:srcCompat="@drawable/..."
      .../>

Upvotes: 3

Biscuit
Biscuit

Reputation: 5257

Per the documentation you have to use android:src="@drawable/attache_file"

Upvotes: 2

Related Questions