Search code examples
javaxmltextview

How can I make this TextView above the FloatingActionButton?


I want to make this textview visible above the FloatinActionButton, but the solutions I've tried didn't work, any other suggestions? Thank you.

[Android Studio screenshot][1] [1]: https://i.sstatic.net/oYBWF.png


Solution

  • First you will need to use Extended FAB instead of FAB. Ok lets start :

    step 1

    add this to your build.gradle (moudle) file

    implementation 'com.google.android.material:material:1.1.0'
    

    at the dependencies

    step 2

    The Extended FAB shape will be rectangle so you should create a drawable resource file and lets call it shape.xml and add this code inside it :

    <?xml version="1.0" encoding="utf-8"?>
    <shape android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
    <size
    android:height="50dp"
    android:width="50dp"/>
    <solid android:color="@color/colorPrimary" />
    </shape>
    

    step 3

    Now , lets create the Extended FAB and it's will be like this :

       <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@drawable/shape"
        android:text="OK"/>
    

    the result :

    enter image description here