9

I am trying to show textview on the top of Floating Action Button. Inside FrameLayout, I have 1 FAB and 1 TextView:

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|start"
    android:padding="@dimen/fab_margin">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabAddSeller"
        android:layout_width="70dp"
        android:layout_height="70dp"
        app:backgroundTint="#3780f4"
        android:stateListAnimator="@null"/>

    <TextView
        android:id="@+id/tvSellRecordCount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/sell_record_counter"
        android:layout_gravity="top|end"
        android:text="12"
        android:textColor="#FFFFFF"
        android:textSize="10sp" />

</FrameLayout>

According to this answer, I have added

android:stateListAnimator="@null"

to FAB - no difference. I have put TextView after FAB - no effect.

enter image description here

How to show another view on top of FloatingActionButton?

Community
  • 1
  • 1
Joe Rakhimov
  • 4,713
  • 9
  • 51
  • 109

2 Answers2

14

In Android Studio, I could fix after adding an elevation to the text view:

android:elevation="6dp"

It seems that FAB has 5dp of elevation.

However, I'm not sure if this totally works to you since elevation is available for API>=21.

Try to make some tests in real devices...

Maybe, android:stateListAnimator="@null" is enough in real devices/emulator.

UPDATE

After adding app:elevation, this fix started to work with older APIs as well

app:elevation="6dp"
android:elevation="6dp"
guipivoto
  • 18,327
  • 9
  • 60
  • 75
1

Replace FrameLayout with RelativeLayout and add

 <android.support.design.widget.FloatingActionButton
        ...
        android:layout_below="@+id/tvSellRecordCount"
        ...
        />
Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69