How to add shadow to the FAB provided with the android support design library?
Simply setting app:borderWidth="0dp"
resolve this issues for me.
Note: don't forget to add xmlns:app="http://schemas.android.com/apk/res-auto"
to your root layout.
This issue should be fixed in next release of android design library.
Fab in Lollipop shows strange shadow on long press
It turned out that the culprit was useCompatPadding
.
Removing it solved the shadow problem.
To fix the margins I used this answer
which basically uses custom margins with two different styles, default and ond for api 21+
But this is in fact an ugly solution and the margins are not perfect, so I am open to better solutions.
How to remove FloatingActionButton's surrounding shadow?
Override the default elevation of the FAB by adding:
android:elevation="0dp"
Or in code call View.setElevation(float)
FAB - square on pre Lollipop and without shadow on Lollipop
Thanks to @harism comment, simply setting app:borderWidth="0dp"
resolve both issues.
Note: don't forget to add xmlns:app="http://schemas.android.com/apk/res-auto"
to your root layout.
Elevation for FAB doesn't work
This is used for an ImageButon, not a FAbButton, but it simulates the Fab:
what you can do it is create a fab-btn.xml in drawable folder to simulate the shadow:
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="false">
<layer-list>
<item android:bottom="0dp" android:left="2dp" android:right="2dp" android:top="2dp">
<shape android:shape="oval">
<solid android:color="#44000000" />
</shape>
</item>
<item android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp">
<shape android:shape="oval">
<solid android:color="@color/orange" />
</shape>
</item>
</layer-list>
</item>
<item android:state_pressed="true">
<shape android:bottom="2dp" android:left="2dp" android:right="2dp" android:shape="oval" android:top="2dp">
<solid android:color="#E73700" />
</shape>
</item>
</selector>
In your main layout on the fab button:
android:background="@drawable/fab_btn"
android:elevation="5dp"
If it is API 21+ it will take the levation, if not it will take the fab_btn.xml. It is up to you to update this file to have the desired shadow
Android design library FAB no shadow
Change xmlns:app="http://schemas.android.com/tools"
to xmlns:app="http://schemas.android.com/apk/res-auto"
.
Related Topics
How to Hide a Folder in Sdcard in Android
Error Non-Default Constructors in Fragments
Installing Ionic Npm Err! Tar.Unpack Error
Android APK File: Re-Activate Older APK File in Google Play Store
Execution Failed for Task App:Transformclasseswithdesugarfordebug Error on Android Studio 3.0 Beta 2
Topics on Firebase Cloud Messaging
Convert String into Localdatetime
Call to 'Getdrawingcache' Returns Null When Scroll Is Enabled
Getting "Caused By: Java.Lang.Verifyerror:"
How to Use Startactivityforresult() for Email Intent
How to Show Dialog in Oncreate Method
How to Verify If User Has Network Access and Show a Pop-Up Alert When There Isn'T
Occured an Internal_Error When Requestemail from Googlesigninoptions Android
Getlastknownlocation() Returns Null
How to Give Everyone Access to Firestore Database, But Only via App
Taking Screenshot Programmatically Doesnt Capture the Contents of Surfaceview