トラッキング コード

5/29/2015

Hot to use FloatingActionButton , Android Support library v22.2

Google had updated Android Support library!!
We can use the Design Support Library which include Material Design components.

http://developer.android.com/tools/support-library/index.html

import library

The following code is sample for Android Studio.
Note : typo in Android Developers site http://developer.android.com/tools/support-library/features.html#design

    compile 'com.android.support:design:22.2.0'

FloatingActionButton

The following code is sample for Layout.

    <android.support.design.widget.FloatingActionButton
            android:id="@+id/floating_action_button"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/XXXX"
            android.support.design:backgroundTint="@color/fab_bg"
            android:contentDescription="@string/XXXX"/>
Default Fab Color is "colorAccent". If use other color, we can set android.support.design:backgroundTint.


Note

Design Library(ver 22.2) has some issues.
FAB doesn't have shadow on Lollipop https://code.google.com/p/android/issues/detail?id=175068
The FloatingActionButton has different margins on Lollipop and pre-Lollipop. https://code.google.com/p/android/issues/detail?id=175330

If not show "Shadow", set "app:borderWidth="0dp".