Floating action button with square shape

When I set the color to my fab, it looks like this:

enter image description here

My xml layout:

<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 does not change. Can someone help me understand what I am doing wrong?

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

Here is the 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> 

+5
source share
4 answers

Using

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

(for example) to set the color fab. The result is lower. Taken from this piece of code-tested code.

enter image description here

Also edit: "weird green" should come from your accent color. That color fab accepts by default.

+4
source

Use this code in xml

Application: 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" /> 
+5
source

just add app:borderWidth="0dp"

0
source

just setting up the application: borderWidth = "0dp" solves the problem.

0
source

All Articles