我正在创建一个Android应用程序,我正在使用AndroidX库和Material设计主题.我的应用主题styles.xml是:
<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>
Run Code Online (Sandbox Code Playgroud)
我从库中有以下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" />
Run Code Online (Sandbox Code Playgroud)
并尝试了默认的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" />
Run Code Online (Sandbox Code Playgroud)
没有图标的颜色(矢量可绘制),FAB内的图标(来自库和默认图标)总是黑色.我已经将问题缩小到材料设计主题,因为使用旧的Theme.AppCompat.Light.DarkActionBar而不是新Theme.MaterialComponents.Light.DarkActionBar的FAB内的图标获得原始矢量drawable的颜色.
有谁知道为什么会发生这种情况以及如何解决这个问题?
android android-theme material-design floating-action-button androidx