Floating Button not showing shadow

时间:2017-06-09 06:58:18

标签: android

I am using vector drawable for floating button. I was wanted to have elevated grey shadow below button. When I preview it in xml it shows me shadow but when I run the application, it doesn't show shadow in device. Any reason why is it happening. Code and Screenshots below :

<android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_add_cg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:elevation="6dp"
        app:borderWidth="0dp"
        app:backgroundTint="@color/blue_4a90e2"
        app:srcCompat="@drawable/add_fab"/>

Vector

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="26dp"
    android:height="24dp"
    android:viewportWidth="26"
    android:viewportHeight="24">

    <group
        android:translateX="-313.000000"
        android:translateY="-550.000000">
        <group
            android:translateX="295.000000"
            android:translateY="532.000000">
            <group
                android:translateX="18.000000"
                android:translateY="18.000000">
                <group
                    android:translateX="7.000000"
                    android:translateY="5.000000">
                    <path
                        android:fillColor="#FFFFFF"
                        android:fillType="evenOdd"
                        android:strokeWidth="1"
                        android:pathData="M 19 11 L 13 11 L 13 5 L 11 5 L 11 11 L 5 11 L 5 13 L 11 13 L 11 19 L 13 19 L 13 13 L 19 13 Z" />
                </group>
                <path
                    android:fillColor="#FFFFFF"
                    android:fillType="evenOdd"
                    android:strokeWidth="1"
                    android:pathData="M13.4558738,12.2931068 C15.3663592,11.1301456 16.6121845,9.05378641
16.6121845,6.645 C16.6123786,2.99019417 13.6219903,0 9.96737864,0 C6.31276699,0
3.32237864,2.99019417 3.32237864,6.645 C3.32237864,9.05378641
4.56839806,11.1303398 6.47868932,12.2931068 C3.15631068,13.538932
0.664466019,16.4462621 0,19.9347573 L1.66131068,19.9347573 C2.49184466,16.113835
5.89747573,13.2898058 9.96737864,13.2898058 C14.0372816,13.2898058
17.4429126,16.113835 18.2734951,19.9347573 L19.9347573,19.9347573
C19.2703398,16.3630097 16.7784951,13.4558738 13.4558738,12.2931068 Z
M4.98368932,6.645 C4.98368932,3.90398058 7.22635922,1.66131068
9.96737864,1.66131068 C12.7083981,1.66131068 14.951068,3.90398058
14.951068,6.645 C14.951068,9.38601942 12.7083981,11.6286893
9.96737864,11.6286893 C7.22635922,11.6286893 4.98368932,9.38601942
4.98368932,6.645 Z" />
            </group>
        </group>
    </group>
</vector>

When I preview: enter image description here

当我跑步时: enter image description here

完整版面码:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    tools:context="com.fragment">

    <LinearLayout
        android:id="@+id/ll_cg_data"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="gone">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:scrollbars="none" />

        <LinearLayout
            android:id="@+id/ll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="@dimen/activity_margin_half"
            android:orientation="vertical">

            <com.lifeontrack.utils.RobotoTextView
                android:id="@+id/tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:text="@string/good"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/grey_464646_85"
                app:font="Roboto-Medium.ttf" />

            <com.lifeontrack.utils.RobotoButton
                android:id="@+id/btn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_margin="@dimen/activity_margin_half"
                android:background="@color/blue_4a90e2"
                android:paddingLeft="10dp"
                android:paddingTop="5dp"
                android:text="@string/add"
                android:textAllCaps="true"
                android:textColor="@color/white"
                android:textSize="16sp"
                app:font="Roboto-Medium.ttf" />
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_cg_no_data"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="gone">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="0.7"
            android:background="@color/blue_eaeff4">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/_no" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".3"
            android:paddingBottom="@dimen/activity_horizontal_margin">

            <com.lifeontrack.utils.RobotoTextView
                android:id="@+id/txt_good_cg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_margin="@dimen/activity_horizontal_margin"
                android:gravity="center_horizontal"
                android:text="@string/good"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="@android:color/black"
                app:font="Roboto-Regular.ttf" />

            <com.lifeontrack.utils.RobotoButton
                android:id="@+id/btn_add_cg"
                style="?android:textAppearanceButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_margin="@dimen/activity_margin_half"
                android:background="@drawable/outline_blue_btn"
                android:text="@string/add"
                android:textAllCaps="true"
                android:textColor="@color/dashboard_icon"
                android:textStyle="bold"
                app:font="Roboto-Medium.ttf" />
        </RelativeLayout>
    </LinearLayout>

    <com.lifeontrack.utils.RobotoTextView
        android:id="@+id/txt_no_records"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/no_records_found"
        android:visibility="gone" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_add_cg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_centerHorizontal="true"
        app:rippleColor="@android:color/white"
        app:pressedTranslationZ="12dp"
        android:layout_margin="@dimen/fab_margin"
        app:elevation="12dp"
        app:borderWidth="0dp"
        app:backgroundTint="@color/blue_4a90e2"
        app:srcCompat="@drawable/add_fab"/>

</FrameLayout>

1 个答案:

答案 0 :(得分:0)

使用CoordinatorLayout获取新资源的所有效果。并且不要忘记添加以下行:xmlns:app="http://schemas.android.com/apk/res-auto"如果您使用<include />

将内容添加到主布局中会更好
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <include layout="@layout/content" />

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        app:elevation="6dp"
        app:borderWidth="0dp"
        app:srcCompat="@drawable/add_fab"
        app:backgroundTint="#4a90e2"/>

</android.support.design.widget.CoordinatorLayout>