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:
Solution 1:
You just need to add an elevation attribute to the textview
<FrameLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><android.support.design.widget.FloatingActionButtonxmlns: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" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#000000"android:text="above"android:elevation="7dp"/></FrameLayout>
Solution 2:
it a z-order problem. In your FrameLayout move the <TextView
above the <FloatingActionButton
<FrameLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#000000"android:text="above"/><android.support.design.widget.FloatingActionButtonxmlns: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" /></FrameLayout>
should do it
Solution 3:
To support low end device use both android:elevation
and app:elevation
set both values to 0 for Fab
<FrameLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><android.support.design.widget.FloatingActionButtonxmlns: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:elevation="0dp"app:fabSize="normal" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#000000"android:text="above"/></FrameLayout>
Solution 4:
Here is your solution :
<FrameLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><RelativeLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content" ><android.support.design.widget.FloatingActionButtonxmlns: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" /><TextViewandroid:layout_toRightOf="@+id/fab"android:layout_marginLeft="-10dp"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#000000"android:text="above"/></RelativeLayout></FrameLayout>
Post a Comment for "How To Add A Textview Above A Floatingactionbutton In Android"