Set hint of textinputlayout ALWAYS above edittext?

Viewed 2663

How do I set the hint of TextInputlayout to be ALWAYS above EditText? That means I don't have to click the EditText to make it slide up. Right now, the hint of EditText and the hint of TextInputLayout are overlapping, I want them to be separated!

My current XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeID"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/messageRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/inputLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"        
            android:hint="My Hint Text"
            app:hintEnabled="true"
            app:hintAnimationEnabled="false">

            <EditText
                android:hint="Type here"
                android:id="@+id/messageEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />

        </android.support.design.widget.TextInputLayout>

    </LinearLayout>

</RelativeLayout>
3 Answers

I just wanted to have the hint always on top too. Must say @Chirag has an important point, but I wanted an easy way for the endIcon functionality.

So very simple workaround: set a blank into the TextInputEditText e.g.

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/hint_text" >

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=" " />

</com.google.android.material.textfield.TextInputLayout>

When processing the input I make sure if the blank was deleted.

Related