我无法使用渐变设置FAB的背景。 FAB的背景显示为black
颜色我的mainActivtiy xml文件在下面给出
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomappbar.BottomAppBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:backgroundTint="@color/colorPrimary"
app:menu="@menu/bottom_nav"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_gradient"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我的自定义渐变文件如下
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<gradient
android:angle="90"
android:startColor="#E12160"
android:endColor="#3F5CC8" />
<size
android:width="56dp"
android:height="56dp" />
</shape>
</item>
<item
android:left="10dp"
android:right="10dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ffffff" />
</shape>
</item>
<item
android:left="10dp"
android:right="10dp">
<rotate
android:fromDegrees="90">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ffffff" />
</shape>
</rotate>
</item>
</layer-list>
我得到的输出如下
我的渐变XML如下所示
经过一番研究后,我知道如果用户未指定,则在FAB属性中将背景设置为默认颜色。如果我们指定的背景不是颜色值,则tint
值会自动设置为黑色(不可用)。因此将其更改为app:tint="@null"
。这样可以确保我们的自定义背景可见