为什么我的浮动操作按钮无法正确显示其图像? [英] Why is my floating action button not displaying its image properly?

查看:136
本文介绍了为什么我的浮动操作按钮无法正确显示其图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的浮动操作按钮显示的内容

它只是显示图像的实际圆形部分,而是尝试将我的.png文件的背景调整到浮动操作按钮中.

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.

这是我的xml代码:

<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?

我已经给了我的.png文件一个透明的背景,所以我不知道我还需要做什么.请帮忙.

I've given my .png file a transparent background already, so I don't know what else I need to do. Please Help.

谢谢.

推荐答案

(假设您使用的是Android Studio)-而不是使用自己的自定义.png作为FloatingActionButton的src,而是使用该图标创建一个新的矢量资产.右键单击Android Studio中的res/drawable文件夹,然后单击新建"->矢量资产".

(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.

您正在使用的图标内置于Android Studio中,但是如果您要进行更多自定义操作,则可以导入自己的矢量素材.它生成的XML将如下所示:

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

,您可以在fillColor中更改颜色.在android:src中将您的FloatingActionButton设置为此可绘制对象,您就很好了.

and you can change the color in fillColor. Set your FloatingActionButton to this drawable in android:src and you're good to go.

这篇关于为什么我的浮动操作按钮无法正确显示其图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆