I am using FloatingActionButton - http://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html
Randomly I see that the shadow is not being drawn properly - it comes out in solid grey as opposed to a gradient.
Here is my markup:
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="24dp"
android:layout_marginRight="24dp"
app:borderWidth="0dp"
android:id="#+id/fabButton"
android:src="#drawable/search"
android:clickable="true" />
Has anybody else faced this?
I think, you forgot these attributes:
...
app:elevation="6dp"
app:pressedTranslationZ="12dp"
...
See this answer for more information about FloatingActionButton design guides
Related
I'm trying to add elevation (shadow) to a com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton and it just doesn't apply
I've tried so far adding:
app:elevation="8dp"
app:borderWidth="0dp"
Even on different order as someone mentioned it may make a difference
Removed the android:background and some other attributes just to see if it collides with the elevation but no luck.
The complete definition currently looks like this:
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/save_reminder_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:text="#string/save"
android:textAllCaps="true"
android:textColor="#color/white"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingStart="15dp"
android:paddingLeft="15dp"
android:paddingRight="20dp"
android:paddingEnd="20dp"
app:elevation="8dp"
app:borderWidth="0dp"
app:icon="#drawable/ic_check_white_18dp"
app:backgroundTint="#color/colorPrimary"
app:layout_anchorGravity="bottom|end" />
The attribute to set the elevation is app:elevation and the default value is 6dp
Use:
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
app:elevation="8dp"
Check your material components library and use the latest stable version (currently 1.2.0).
use:
android:stateListAnimator="#null"
and
android:elevation="2dp"
I am getting light grey color below the FloatingActionButton as shown in image. Any one know how to remove it. I tested it on Lollipop version.
My xml code
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/ic_add_black"
app:borderWidth="0dp"
app:fabSize="mini"
app:rippleColor="#color/colorPrimaryDark" />
Try set elevation:
app:elevation="0dp"
It happens when you set an elevation and the fab element has not space enough to display the "shadow".
Then you can set the elevation as 0dp as suggested above, or set a margin like
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_build_white_36dp"
android:id="#+id/build"
app:elevation="4dp"
android:clickable="true"
android:layout_margin="10dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
In this way the "elevation-effect" will appear correctly
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" />
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" />
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" />
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"
i faced the similar problem. I tried to set src or background of FloatingActionButton, but couldn't fill the button by src. following code solved problem for me.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
.
.
.
android:background="#drawable/round_icon"
android:backgroundTintMode="src_over">
I am using FloatingActionButton for api 21+ its showing perfectly ok but if i look it in api 20- then it has four lines in the background.
Below is the xml code of my FloatingActionButton
<android.support.design.widget.FloatingActionButton
android:id="#+id/bt_ok"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="#drawable/ic_done"
app:backgroundTint="#color/primary"
app:borderWidth="0dp" />
The screen for api 21+
The screen for api 20-
Just look at the four thick lines below the FloatingActionButton in the second screen and give me a solution for removing that.
I got the answer for my own question just change the height and width to wrap_content and the problem is solved.
<android.support.design.widget.FloatingActionButton
android:id="#+id/bt_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="#drawable/ic_done"
app:backgroundTint="#color/primary"
app:borderWidth="0dp" />
With the help of this question I built a Floating Action Button to add elements to my Listview
The code is easy:
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
app:backgroundTint="#color/spg_rosa"
app:borderWidth="0dp"
app:elevation="4dp"
app:fabSize="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_white_48dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
/>
The thing is
app:elevation="4dp"
is not working, I can't see any shadow!
I grab the icon from Google : https://www.google.com/design/icons/
Any idea?
EDIT: I'm using it in Samsung S3 Mini ( API 16 )
I just tested your sample on a Samsung S3 Mini (API 16).
For me the elevation works.
because the elevation value is so small it's not very visible, try to increase the value. As BrentM says the elevation is not working if app:borderWidth="0dp" is not added.
Your problem is the "android:layout_alignParentBottom="true", that means your button is right at the bottom edge, try adding at least 10dp of margin at the bottom and it will fix your problem.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
app:backgroundTint="#color/spg_rosa"
app:borderWidth="0dp"
app:elevation="4dp"
app:fabSize="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_white_48dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="10dp"
/>
Regards!
Thing was My Listview were black!
I changed color theme to white, and I could see the shadow !