方形浮动动作按钮 [英] Floating Action Button with square shape

查看:89
本文介绍了方形浮动动作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我为工厂设置颜色时,它看起来像这样:

When I set a color to my fab, it looks like so:

我的布局xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment">

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_add"
    android:layout_marginRight="20dp"
    app:fabSize="normal"
    android:elevation="@dimen/fab_elevation"
    android:background="#000000"
    android:stateListAnimator="@animator/fab_anim"
    android:layout_gravity="center_horizontal"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true" />

颜色也不会更改。
有人可以帮助我了解我在做什么吗?

Also the color doesn't change. Can anyone help me in understanding what I am doing wrong?

我也尝试过使用 @color 链接,但它以可绘制(例如android:background = @ drawable / fab_background)的背景崩溃了。没有任何反应。

I also tried with a @color link but it crashed, with the background of a drawable (ex. android:background="@drawable/fab_background") nothing happens.

这是可绘制的 fab_background.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item>
    <ripple android:color="@color/fab_color_1_muted">
        <item>
            <shape>
                <solid android:color="@color/fab_color_1" />
            </shape>
        </item>
    </ripple>
</item>

推荐答案

使用

app:backgroundTint="@android:color/holo_green_dark"

(例如)设置工厂的颜色。结果如下。 来自经过测试的代码段。

(for example) to set color of fab. Result below. Taken from this -tested- code snippet.

还可以编辑:奇怪的绿色应该来自您的强调色。这是彩色工厂默认情况下采用的颜色。

Also edit : "strange green color" should come from your accent color. That's the color fab takes by default.

这篇关于方形浮动动作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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