Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 997
comrade Avatar asked Nov 12 '15 12:11

comrade


People also ask

How do I add an image to a floating action button?

Add the floating action button to your layout The size of the FAB, using the app:fabSize attribute or the setSize() method. The ripple color of the FAB, using the app:rippleColor attribute or the setRippleColor() method. The FAB icon, using the android:src attribute or the setImageDrawable() method.

How do you add text to floating action button on flutter?

Add a Text("YourText") widget in child of FloatingActionButton. Then it will work.

What is extended floating action button?

Extended Floating Action Button is the newly introduced class with Material Components library in Android. Material Components is introduced with SDK 28 or Android P. It's a superset of Support Design Library with lots of new additions and improvements.


1 Answers

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> 
like image 175
comrade Avatar answered Sep 28 '22 09:09

comrade