为什么我的浮动操作按钮无法正确显示其图像? [英] Why is my floating action button not displaying its image properly?
问题描述
您使用的图标内置于 Android Studio 中,但如果您要进行更自定义的操作,则可以导入自己的矢量资源.它生成的 XML 将如下所示:
<路径android:fillColor="#FF000000"android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
并且您可以在fillColor中更改颜色.在 android:src 中将您的 FloatingActionButton 设置为此可绘制对象,您就可以开始了.
This is what my floating action button is showing
rather that just showing the actual circle part of the image, it tries to fit the background of my .png file into the floating action button.
here is my xml code:
<android.support.design.widget.FloatingActionButton
android:id="@+id/addToKitchenButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_gravity="bottom|end"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:src="@drawable/fab_icon"
/>
how do I get it to look like this?
I've given my .png file a transparent background already, so I don't know what else I need to do. Please Help.
Thank You.
(Assuming you are using Android Studio) -- Rather than using your own custom .png for the FloatingActionButton's src, create a new vector asset with that icon. Right click your res/drawable folder in Android Studio, and then click to New -> Vector Asset.
The icon you are using is built in to Android Studio, although you could import your own vector asset if you were doing something more custom. The XML it generates will look like this:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
and you can change the color in fillColor. Set your FloatingActionButton to this drawable in android:src and you're good to go.
这篇关于为什么我的浮动操作按钮无法正确显示其图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!