我正在创建一个 Android 应用程序,并使用 AndroidX 库和 Material design 主题。我的应用程序主题为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:
<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:
<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 内的图标获取原始矢量可绘制的颜色。
有谁知道为什么会发生这种情况以及如何解决它?
我通过使用解决了这个问题:
app:tint="@color/COLOR_OF_ICON"
and NOT:
android:tint="@color/COLOR_OF_ICON"
参考:https://github.com/material-components/material-components-android/blob/master/docs/components/FloatingActionButton.md https://github.com/material-components/material-components-android/blob/master/docs/components/FloatingActionButton.md
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)