【发布时间】:2020-03-10 15:41:10
【问题描述】:
有人可以分享如何为浮动操作按钮实现渐变背景吗?
我想实现这样的目标:
我尝试使用下面的drawable:
<?xml version="1.0" encoding="utf-8"?>
<item>
<shape android:shape="oval">
<gradient
android:type="linear"
android:angle="0"
android:startColor="#f6ee19"
android:endColor="#115ede" />
</shape>
</item>
<item android:gravity="center"
>
<bitmap android:src="@drawable/ic_close_accent"
android:gravity="fill_horizontal" />
</item>
然后在我的活动中,我将 android:src 设置为这个可绘制对象,但它不起作用
我也尝试设置 android:backgroundTint 和 android:background 但这些也没有用。
有人可以帮忙吗?
【问题讨论】:
-
您需要使用
app命名空间而不是android命名空间。见这里:How to change FAB background color -
@Anmol 你能仔细阅读我的问题吗?
-
@ChrisStillwell 我刚试过,还是不行。
-
@CodeWithVikas android:background 不适合我。您是否在 FAB 上尝试过此代码?
标签: android android-layout gradient floating-action-button