我正在使用浮动操作按钮,我想更改背景颜色。
这是我的代码
<android.support.design.widget.FloatingActionButton
android:id="@+id/btnfab"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="right|center_vertical"
android:layout_marginBottom="20dp"
android:src="@drawable/search" />
以下是我用来尝试实现此目的的代码:
1- android:background="@color/mycolor"
2- android:backgroundTint="@color/white"
如图所示,我也在我的FAB上找到了一个角落。我该如何删除那些角落阴影?
答案 0 :(得分:30)
您可以通过将此属性添加到app:borderWidth="0dp"
app:elevation="6dp"
:
FloatingActionButton
app:backgroundTint="@color/YOURCOLOR"
没有背景色。您可以通过以下方式更改此组件颜色:
xmlns:app="http://schemas.android.com/apk/res-auto"
请记住在您的父级布局中使用以下行:
+
答案 1 :(得分:9)
在您的应用程序样式中声明以下内容:
<item name="colorAccent">@color/yourColor</ item>
欢呼声
答案 2 :(得分:6)
请在build.gradle
更新您的Android支持和Android材料设计库。
(请在上面添加你的build.gradle文件)
根据这些网站:
和Android Developers reference你应该只使用:
android:backgroundTint="@color/white"
我记得,这个影子是浮动动作按钮众所周知的问题,所以请看一下这些额外的库:
http://android-arsenal.com/tag/173
可以帮助您替换这个破碎的元素。
检查:
希望有所帮助。
答案 3 :(得分:3)
首先在您的styles.xml中创建样式:
<style name="PrimaryActionButton" parent="Theme.AppCompat.Light">
<item name="colorAccent">@color/colorPrimary</item>
</style>
然后将晶圆厂的主题设置为此样式:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_favorite_white_24dp"
android:theme="@style/PrimaryActionButton"
app:fabSize="normal"
app:rippleColor="@color/colorAccent" />
您可以在以下位置看到完整的说明: Android: Floating Action button