Android FAB图标始终以MaterialComponents主题为黑色 [英] Android FAB icon always black with MaterialComponents theme

查看:383
本文介绍了Android FAB图标始终以MaterialComponents主题为黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Android应用,并且正在使用AndroidX库和Material design主题.我在styles.xml上的应用主题是:

I'm creating an Android app and I'm using the AndroidX libraries and Material design theme. My app theme on styles.xml is:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

我从自定义库中获得了以下FAB:

I have the following FAB from a custom library:

<com.leinardi.android.speeddial.SpeedDialView
        android:id="@+id/work_log_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        app:layout_behavior="@string/speeddial_scrolling_view_snackbar_behavior"
        app:sdMainFabClosedSrc="@drawable/ic_add_white_24dp"
        app:sdOverlayLayout="@id/overlay" />

还尝试了默认的FAB:

And also tried the default FAB:

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:src="@drawable/ic_add_white_24dp"
        android:layout_margin="16dp" />

图标(可绘制矢量)的颜色没有问题,FAB内部的图标(来自库和默认值)始终为黑色.我将问题缩小到了材料设计主题,因为使用旧的Theme.AppCompat.Light.DarkActionBar而不是新的Theme.MaterialComponents.Light.DarkActionBar,FAB中的图标获得了可绘制的原始矢量的颜色.

No mater the color of the icon (a vector drawable), the icon inside the FAB (from the library and from the default) is always black. I have narrowed down the problem to the material design theme, since using the old Theme.AppCompat.Light.DarkActionBar instead of the new Theme.MaterialComponents.Light.DarkActionBar the icon inside the FAB gets the color of the original vector drawable.

有人知道为什么会这样以及如何解决吗?

Does anyone know why this is happening and how to solve it?

推荐答案

我使用以下方法解决了此问题:

I solved this by using:

app:tint="@color/COLOR_OF_ICON"

:

android:tint="@color/COLOR_OF_ICON"

参考: https://github.com/material-components/material-components-android/blob/master/docs/components/FloatingActionButton.md

这篇关于Android FAB图标始终以MaterialComponents主题为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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