简体   繁体   English

方形浮动动作按钮

[英]Floating Action Button with square shape

When I set a color to my fab, it looks like so: 当我为工厂设置颜色时,它看起来像这样:

在此处输入图片说明

My layout xml: 我的布局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? 谁能帮助我了解我在做什么错?

I also tried with a @color link but it crashed, with the background of a drawable (ex. android:background="@drawable/fab_background") nothing happens. 我也尝试了@color链接,但是它崩溃了,并且背景为drawable (ex. android:background="@drawable/fab_background")没有任何反应。

Here is the drawable fab_background.xml 这是可绘制的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>

Use this code in your xml 在您的xml中使用此代码

app:borderWidth="0dp" app:borderWidth =“ 0dp”

<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"
    app:borderWidth="0dp"
    android:stateListAnimator="@animator/fab_anim"
    android:layout_gravity="center_horizontal"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true" />

Use 使用

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

(for example) to set color of fab. (例如)设置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. 这是默认情况下的彩色fab。

只需添加app:borderWidth="0dp"

只需设置app:borderWidth =“ 0dp”即可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM