为FloatingActionButton设置src和背景 [英] Setting src and background for FloatingActionButton

查看:1102
本文介绍了为FloatingActionButton设置src和背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆