首页 > 解决方案 > 浮动操作按钮未在 Android 中显示图像?

问题描述

正如标题所说,我不知道如何解决这个问题。我读过这个问题,但那是在 2018 年,我对所有这些库和依赖项都不是很熟悉。但是从我声明的依赖项来看,从 Android Studio 来看,这就是我得到的:

在此处输入图像描述

我想在 FAB 中添加某种“附加文档”图标/图像。我试图通过添加新矢量资产来做到这一点,但图像没有出现在我的可绘制文件夹中。如何找到一些不错的图标/图像并将其设置为 FAB?

这是 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>

标签: androidxmlfloating-action-buttonmaterial-components-android

解决方案


我找到了解决方案,只需在 dimens.xml 中添加以下语句

<dimen name="design_fab_image_size" tools:override="true">56dp</dimen>

并且必须在您的 FAB 设计 xml中添加app:tint="@null"

<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 :) 

推荐阅读