Spe*_*eed 8 xml android android-layout floating-action-button
SO上的其他答案都没有帮助我。
这是我的 FAB xml:
<com.google.android.material.floatingactionbutton.FloatingActionButton xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fabTransfer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:fabCustomSize="@dimen/fab_size_normal"
android:layout_margin="16dp"
app:srcCompat="@drawable/ic_add_white_24dp" />
Run Code Online (Sandbox Code Playgroud)
这是图标xml:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
Run Code Online (Sandbox Code Playgroud)
然而我的图标看起来像这样!
任何想法发生了什么?我也尝试过其他图标(png 和矢量),但还是一样。
解决方案是向 FAB 添加一种样式,该样式扩展了Widget.MaterialComponents.FloatingActionButton
<style name="MyFabStyle" parent="Widget.MaterialComponents.FloatingActionButton">
<item name="backgroundTint">@color/fab_background</item>
<item name="rippleColor">#0d9bed</item>
</style>
Run Code Online (Sandbox Code Playgroud)