Disable/Remove floating label hint text in TextInputLayout XML

Micro picture Micro · Feb 16, 2016 · Viewed 54.4k times · Source

This may seem counter-intuitive but is there a way to disable or remove the floating label hint in TextInputLayout? The reason I want to use TextInputLayout instead of just an EditText is for the counter that TextInputLayout provides.

Here is what I have so far:

<android.support.design.widget.TextInputLayout
            android:id="@+id/textContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            app:counterEnabled="true"
            app:counterMaxLength="100">

            <EditText
                android:id="@+id/myEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" 
                android:gravity="top|left"
                android:inputType="textMultiLine|textCapSentences"
                android:maxLength="100"
                android:scrollbars="vertical"
                android:hint="This is my cool hint"/>

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

Answer

Gauthier picture Gauthier · Apr 27, 2016

Starting version 23.2.0 of the Support Library you can call

setHintEnabled(false)

or putting it in your TextInputLayout xml as such :

app:hintEnabled="false"

Though the name might makes you think it removes all hints, it just removes the floating one.

Related docs and issue: http://developer.android.com/reference/android/support/design/widget/TextInputLayout.html#setHintEnabled(boolean)

https://code.google.com/p/android/issues/detail?id=181590