Android设计库FAB无阴影

Android design library FAB no shadow

出于某种原因,我的 FAB 没有显示阴影,即使我已将高度和边框宽度设置为 0,就像许多博客中描述的那样。那应该可以解决问题。我将 fab 放在工具栏上方以获得 material 设计指南外观。

这是我的代码:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include android:id="@+id/toolbar" layout="@layout/toolbar_extended" />

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_navigate"
        android:layout_alignParentRight="true"
        android:layout_marginTop="88dp"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="16dp"
        app:backgroundTint="@color/accent_yellow"
        app:borderWidth="0dp"
        app:elevation="8dp"
        app:pressedTranslationZ="12dp"
        app:fabSize="normal"
        app:rippleColor="@color/accent_dark_yellow" />

</RelativeLayout>

工具栏:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="116dp"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    android:fitsSystemWindows="true"
    android:minHeight="?android:attr/actionBarSize"
    app:navigationIcon="@drawable/abc_ic_ab_back_mtrl_am_alpha"/>

xmlns:app="http://schemas.android.com/tools" 更改为 xmlns:app="http://schemas.android.com/apk/res-auto"

设置

app:borderWidth="0dp" 除了添加命名空间 xmlns:app="http://schemas.android.com/apk/res-auto"