简体   繁体   中英

How to add PNG to floating action button in android

I want to display this png as my floating action button. But when I set this as my src, I get a black icon instead. How can I do it?

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@null"
        android:backgroundTint="@null"
        android:cropToPadding="true"
        android:outlineSpotShadowColor="@null"
        android:src="@drawable/ic_esaathi_icon"
        app:borderWidth="0dp"
        app:elevation="6dp"
        app:maxImageSize="56dp" />

Edit: Sarath Siva's answer works fine.

app:srcCompat="@drawable/icon_02"

在此处输入图片说明

use it like this

 <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/icon_02"
        android:scaleType="center"
        app:maxImageSize="56dp"
        app:tint="@null"
        />

remove background, try to set eg transparent or white color (or @null ), but use custom lib attributes (eg app: ) instead of built-in ones ( android: )

app:backgroundTint="@android:color/transparent"
app:tint="@android:color/transparent"

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