为FloatingActionButton设置src和背景 [英] Setting src and background for FloatingActionButton
问题描述
当我在android.support.design.FloatingActionbutton中使用background和src时,设置不正确.而是显示为
When I use background and src in android.support.design.FloatingActionbutton it is not set correctly. Instead it is displayed as
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/pink"
android:src="@drawable/ic_action_barcode_2"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp" />
但是当我使用ImageView时,它正确显示为
but when I use ImageView it appears correctly as
<ImageView
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/pink"
android:src="@drawable/ic_action_barcode_2"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp" />
为什么FloatingActionButton不能正确显示?我应该更改我的代码吗?
why is FloatingActionButton is not displayed correctly? What should I change in my code?
推荐答案
浮动操作按钮的背景不需要更改,您只需应用一种色调,然后照常添加图标即可
Floating action button's background does not need to be changed, you just apply a tint and then add your icon as usual
<android.support.design.widget.FloatingActionButton
...
app:backgroundTint="@color/ic_action_barcode_2"
android:src="@drawable/ic_add" />
这将为您提供一个圆形按钮,但颜色仍为您想要的颜色.
在这种情况下,app
命名空间用于支持库功能:
This provides you with a round button still but in the colour you desire.
In this case the app
namespace is used for the support library features:
xmlns:app="http://schemas.android.com/apk/res-auto"
这篇关于为FloatingActionButton设置src和背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!