Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove FloatingActionButton's surrounding shadow?

I'm trying to replace the third party FloatingActionButton with the native one which is packaged in library com.android.support:design:22.2.0.The default look has a dark shadow around the image,How can I get rid of it? I know the former one provides with the method setShadow(),but I just can't find similar one from the latter.

enter image description here

This is the related XML layout:

<android.support.design.widget.FloatingActionButton         android:id="@+id/alarm_front"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/btn_icon_alarm_notset" /> 

And I have set its background color to yellow.

mAlarmBtn.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.floatButtonColor))); 
like image 501
tounaobun Avatar asked Jun 03 '15 07:06

tounaobun


People also ask

How do I remove shadow from floating action button?

To remove shadow of Floating Action Button in Kotlin Android, set the elevation attribute (in layout file) to 0dp or set compatElevation parameter (in Kotlin program) of FAB with floating point value of 0.0f.

How do I hide the floating action button?

To show and hide a FloatingActionButton with the default animation, just call the methods show() and hide() . It's good practice to keep a FloatingActionButton in the Activity layout instead of putting it in a Fragment, this allows the default animations to work when showing and hiding.

How do you adjust a floating button?

Add the floating action button to your layoutThe size of the FAB, using the app:fabSize attribute or the setSize() method. The ripple color of the FAB, using the app:rippleColor attribute or the setRippleColor() method. The FAB icon, using the android:src attribute or the setImageDrawable() method.

How do you change the background of a floating action button?

To change background color of Floating Action Button in Kotlin Android, set the backgroundTint attribute (in layout file) or backgroundTintList property (in Kotlin file) of FAB with the required color.


2 Answers

Override the default elevation of the FAB by adding:

android:elevation="0dp" 

Or in code call View.setElevation(float)

like image 128
BrentM Avatar answered Oct 03 '22 04:10

BrentM


Add this

android:elevation="0dp" app:elevation="0dp"

It's will be like :

 <android.support.design.widget.FloatingActionButton         android:id="@+id/floatingActionButton"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/ic_add"         android:elevation="0dp"         app:elevation="0dp"         app:fabSize="normal"         android:scaleType="fitCenter"/> 
like image 22
Jean-Nicolas Defossé Avatar answered Oct 03 '22 04:10

Jean-Nicolas Defossé