android 如何将 PNG 添加到浮动操作按钮
How to add PNG to floating action button in android
我想改为显示 this png as my floating action button. But when I set this as my src, I get a black icon。我该怎么做?
<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" />
编辑:
Sarath Siva 的回答很好。
app:srcCompat="@drawable/icon_02"
删除背景,尝试设置例如透明或白色(或@null
),但使用自定义库属性(例如app:
)而不是内置属性(android:
)
app:backgroundTint="@android:color/transparent"
app:tint="@android:color/transparent"
这样使用
<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"
/>
我想改为显示 this png as my floating action button. But when I set this as my src, I get a black icon。我该怎么做?
<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" />
编辑: Sarath Siva 的回答很好。
app:srcCompat="@drawable/icon_02"
删除背景,尝试设置例如透明或白色(或@null
),但使用自定义库属性(例如app:
)而不是内置属性(android:
)
app:backgroundTint="@android:color/transparent"
app:tint="@android:color/transparent"
这样使用
<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"
/>