简体   繁体   中英

Floating Action Button is not showing an image in Android?

As title is saying, 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:

在此处输入图像描述

I would like to add some kind of "Attach document" icon/image to the FAB. I tried to do that by add New Vector asset, but image do not appear in my drawable folder. How to find some nice icone/image and set it to 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>

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/..."
      .../>

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 :) 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM