Floating Action Button no shadow showing [duplicat

2019-08-18 03:55发布

问题:

This question already has an answer here:

  • How to add shadow to the FAB provided with the android support design library? 6 answers

I am trying to get a shadow under my Floating action button but its not showing.

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="20dp"
    android:background="@color/colorAccent"
    android:clickable="true"
    android:scaleX="-1"
    android:src="@drawable/ic_share"
    app:borderWidth="0dp"
    app:elevation="21dp"
    app:fabSize="normal"
    app:itemIconTint="@color/white" />

<Custom View/>

This is how it shows now:

What am i doing wrong?

Edit 1: The suggested fix to add app:borderWidth="0dp" doesn't fix my problem

Edit 2: Problem solved apparently using android:scaleX="-1" removes the shadow

回答1:

you need to just add app:borderWidth="0dp" to your FloatingActionButton

Sample code

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="20dp"
    app:borderWidth="0dp"
    android:background="@color/colorAccent"
    android:clickable="true"
    android:src="@drawable/ic_share"
    app:borderWidth="0dp"
    app:elevation="21dp"
    app:fabSize="normal"
    app:itemIconTint="@color/white" />

and make sure

Check manifest file in Application tag and delete them

android:hardwareAccelerated="false"
android:largeHeap="true"

But if you need these options then shadows and transformation animations will not work