Add label next to floating action button

Babbara :

I'm trying to add a label next to my Floating Action Button with the tag app:fab_label in each element, but it doesn't show up. This is my code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="49dp"
        android:layout_marginLeft="49dp"
        android:layout_marginEnd="49dp"
        android:layout_marginRight="49dp"
        android:text="Search"
        android:textColor="#ffffff"
        android:textSize="@dimen/_20ssp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <EditText
        android:id="@+id/search_field"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="1dp"
        android:layout_marginLeft="1dp"
        android:layout_marginTop="12dp"
        android:layout_marginEnd="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/search_layout"
        android:ems="10"
        android:fontFamily="@font/nunito_bold"
        android:hint="Search here"
        android:inputType="textPersonName"
        android:paddingLeft="20dp"
        android:paddingTop="10dp"
        android:paddingRight="20dp"
        android:paddingBottom="10dp"
        android:textColor="@color/colorPrimary"
        android:textColorHint="@color/colorPrimary"
        android:textSize="16sp"
        app:layout_constraintEnd_toStartOf="@+id/search_btn"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/search_btn" />

    <ImageButton
        android:id="@+id/search_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:background="@color/cardview_shadow_end_color"
        android:paddingTop="17dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/search_field"
        app:layout_constraintTop_toBottomOf="@+id/textView2"
        app:srcCompat="@mipmap/search_button" />


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/popular_rc_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/search_field">

    </androidx.recyclerview.widget.RecyclerView>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="16dp"
        android:scaleType="center"
        android:src="@drawable/recent_icon"
        android:visibility="invisible"
        app:fab_label="Most Recent"
        app:backgroundTint="@color/colorFabIcon"
        app:elevation="6dp"
        app:maxImageSize="35dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/fab2"
        app:pressedTranslationZ="12dp" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="18dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="16dp"
        android:scaleType="center"
        app:fab_label="Most Rated"
        android:src="@drawable/rated_icon"
        android:visibility="invisible"
        app:backgroundTint="@color/colorFabIcon"
        app:elevation="6dp"
        app:maxImageSize="35dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/fab1"
        app:pressedTranslationZ="12dp" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="16dp"
        android:scaleType="center"
        android:src="@drawable/pop_icon"
        android:visibility="invisible"
        app:backgroundTint="@color/colorFabIcon"
        app:elevation="6dp"
        app:maxImageSize="35dp"
        app:fab_label="Most Popular"
        app:layout_constraintBottom_toTopOf="@+id/fab"
        app:layout_constraintEnd_toEndOf="parent"
        app:pressedTranslationZ="12dp" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="@dimen/_23sdp"
        android:layout_marginBottom="@dimen/_20sdp"
        android:scaleType="centerInside"
        android:src="@drawable/filter"
        app:backgroundTint="@color/colorPrimary"
        app:elevation="6dp"
        app:maxImageSize="35dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:pressedTranslationZ="12dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

Can this be caused since I used the signature com.google.android.material.floatingactionbutton.FloatingActionButton instead of the standard one which starts with android...?

pranav malayil :

just change it to android:text and put your string there.. If this doesn't solve your problem use Extended floating action button there you can set text using android:text property

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=342502&siteId=1