Search code examples
androidmaterial-designandroid-support-libraryfloating-action-button

FloatingActionButton with text instead of image


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?


Solution

  • With API 28 you can simply add text to Fabs using:

    Visit: https://material.io/develop/android/components/extended-floating-action-button/

     <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="8dp"
          android:contentDescription="@string/extended_fab_content_desc"
          android:text="@string/extended_fab_label"
          app:icon="@drawable/ic_plus_24px"
          app:layout_anchor="@id/app_bar"
          app:layout_anchorGravity="bottom|right|end"/>