带有 MaterialComponents 主题的 Android FAB 图标始终为黑色 [英] Android FAB icon always black with MaterialComponents theme
问题描述
我正在创建一个 Android 应用程序,我正在使用 AndroidX 库和材料设计主题.我在 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 内部获取原始矢量 drawable 的颜色.
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"
这篇关于带有 MaterialComponents 主题的 Android FAB 图标始终为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!