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"
Related
this is my FloatingActionButton
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/white"
android:focusable="true"
android:src="#drawable/ic_camera_24"
android:tint="#color/green"
app:fabSize="mini"
app:rippleColor="#color/green" />
i tried to change color in layout ic_camera_24.xml but it still not work, how can i fix it?
have a nice day, everyone!
try this with app:srcCompat and app:tint:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/white"
android:focusable="true"
app:srcCompat="#drawable/ic_camera_24"
app:tint="#color/green"
app:fabSize="mini"
app:rippleColor="#color/green" />
src: https://material.io/components/buttons-floating-action-button/android#mini-fabs
I am using a FAB widget and I want to add a 2 coloured icon in it. Is that possible? This is my current code right now:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/notificationFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
android:tintMode="multiply"
android:backgroundTint="#color/colorWhite"
android:layout_marginTop="5dp"
app:tint="#color/colorPrimaryLight"
app:rippleColor="#color/colorPrimary"
android:layout_marginHorizontal="10dp"
android:src="#drawable/active_notif_final"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:borderWidth="0dp"
/>
I did a workaround: made the colors of the icon light and added tintMode as multiply to get the original color. But it still doesn't look good.
workaround
Original
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/notificationFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorWhite"
android:layout_marginTop="5dp"
app:rippleColor="#color/colorPrimary"
android:layout_marginHorizontal="10dp"
app:icon="#drawable/active_notif_final"
app:iconTint="#color/colorPrimaryLight"
app:iconTintMode="multiply"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:borderWidth="0dp"
/>
with extended FAB:
By default, the icon (app:srcCompat) is tinted with the app:tint color as per the FloatingActionButton documentation.
You can disable this behavior by adding app:tint="#null" to your fab:
<com.google.android.material.floatingactionbutton.FloatingActionButton
app:srcCompat="#drawable/..."
app:tint="#null"
.../>
In the ExtendedFloatingActionButton the app:icon is tinted with the app:iconTint:
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
app:icon="#drawable/...."
app:iconTint="#null"
.../>
i have created and android project in my xml file there is a floating bar like below
<android.support.design.widget.FloatingActionButton
android:id="#+id/btn_cart"
android:src="#drawable/ic_shopping_cart_black_24dp"
android:backgroundTint="#android:color/white"
android:elevation="6dp"
app:pressedTranslationZ="12dp"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
app:useCompatPadding="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
in my activity i have use like below
FloatingActionButton btnCart;
and in side on create
btnCart = (FloatingActionButton) findViewById(R.id.btn_cart);
when i go to that page app will crash I dont know what did I do wrong
As per my comment remove android:backgroundTint. You can change background color in following ways:
In XML with attribute app:backgroundTint
<android.support.design.widget.FloatingActionButton
android:id="#+id/btn_cart"
android:src="#drawable/ic_shopping_cart_black_24dp"
app:backgroundTint="#android:color/white"
android:elevation="6dp"
app:pressedTranslationZ="12dp"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
app:useCompatPadding="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Or in java file
btnCart.setBackgroundTintList(ColorStateList.valueOf(your color in int));
I think the error will be in this line:
android:src="#drawable/ic_shopping_cart_black_24dp"
Make ur changes in the third line of code as:
app:srcCompat="#drawable/ic_shopping_cart_black_24dp"
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
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