Height doesn't work on android.support.design.widget.FloatingActionButton

I just started Android development and tried a new material design. Hereis a screenshot of my mainactivity that has a FloatingActionButton, but it does not apply any enhancement (no shadows).

How to enable shadow for this new widget (android.support.widget.FloatingActionButton).

This is the code from the xml layout

<android.support.design.widget.FloatingActionButton
        android:id="@+id/add_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_add_action"
        android:layout_margin="16dp"
        android:elevation="10dp"
        android:padding="10dp"/>
Run code

Any help appreciated. Thanks

Please note: I would like to use the Android design library only for other github libraries.

+4
source share
3 answers

After many studies, I found the right way to use FAB without any problems. Use the following code as a template:

<android.support.design.widget.FloatingActionButton
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/your_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="@dimen/floating_button_margin_bottom"
        android:layout_marginRight="@dimen/floating_button_margin_right"
        app:elevation="@dimen/floating_button_elevation"
        app:borderWidth="0dp"
        app:rippleColor="@color/your_ripple_color"
        app:backgroundTint="@color/your_bg_color" />
+16

. .

app:borderWidth="0dp" , . , .

+7

Your XML layout may skip the following code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   app:xmlns="http://schemas.android.com/apk/res-auto"
   ... >
         <android.support.design.widget.FloatingActionButton
            ... 
            app:borderWidth="0dp"
            app:elevation="4dp" />
   ... 
</RelativeLayout>

EDIT

For more information, FloatingActionButtonsee this post explaining the problem and design guide.

+6
source

All Articles