'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:
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>
Solution 1:[1]
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 :)
Solution 2:[2]
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/..."
.../>
Solution 3:[3]
Per the documentation you have to use android:src="@drawable/attache_file"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Abdul Rizwan |
Solution 2 | Gabriele Mariotti |
Solution 3 | Biscuit |