Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a TextView above a FloatingActionButton in Android

I want to add a TextView above a FloatingActionButton, I use the FrameLayout as the parent layout of the TextView and FloatingActionButton, here is my sample code:

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <android.support.design.widget.FloatingActionButton
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="#00fff0"
        app:borderWidth="0dp"
        android:elevation="0dp"
        app:fabSize="normal" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:text="above"/>

</FrameLayout>

but it's useless, the TextView is below the FloatingActionButton, like this enter image description here

and I want it show like this: enter image description here

I am poor for this, can anyone help me?

like image 934
naiyu Avatar asked Nov 27 '15 08:11

naiyu


1 Answers

You just need to add an elevation attribute to the textview

 <FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <android.support.design.widget.FloatingActionButton
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="#00fff0"
        app:borderWidth="0dp"
        android:elevation="0dp"
        app:fabSize="normal" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:text="above"
        android:elevation="7dp"/>

</FrameLayout>
like image 61
curiousMind Avatar answered Sep 21 '22 06:09

curiousMind