Android 中的浮动操作按钮不显示图像?

Wra*_*per 3 xml android floating-action-button material-components-android

正如标题所说,我不知道如何解决这个问题。我读过这个问题,但那是在 2018 年,我不太熟悉所有这些库和依赖项及其工作原理。但从我从 Android Studio 声明的依赖关系来看,这就是我得到的:

在此输入图像描述

我想向 FAB 添加某种“附加文档”图标/图像。我尝试通过添加New Vector资源来做到这一点,但图像没有出现在我的可绘制文件夹中。如何向我的项目添加漂亮的图标/图像,并将其设置为 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>
Run Code Online (Sandbox Code Playgroud)

Abd*_*wan 5

我找到了解决方案,只需在 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 :) 
Run Code Online (Sandbox Code Playgroud)