FloatingActionButton with text instead of image

comrade picture comrade · Nov 12, 2015 · Viewed 83.6k times · Source

I'm trying to figure out how can be modified FloatingActionButton from android support library. Can it be used with the text instead of image?

Something like this one:

enter image description here

I see it extends ImageButton so I think not. Am I right?

Is this correct in terms of Material Design in general?

Answer

comrade picture comrade · Nov 12, 2015

Thanks to all.

Here is easy workaround which I found for this question. Works correctly for Android 4+, for Android 5+ is added specific parameter android:elevation to draw TextView over FloatingActionButton.

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:color/transparent" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@android:string/ok"
        android:elevation="16dp"
        android:textColor="@android:color/white"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</FrameLayout>