Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable/Remove floating label hint text in TextInputLayout XML

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> 
like image 368
Micro Avatar asked Feb 16 '16 04:02

Micro


People also ask

How do I get rid of hint in TextInputLayout?

Enabling/Disabling Floating Hints Floating Hints are enabled by default in a TextInputLayout. To disable it we need to add the following attribute inside the tag : app:hintEnabled="false" .

How do you set different gravity for TextInputLayout hint and text in Android?

To set a different gravity for the EditText , don't set any gravity attributes in the layout, then set the EditText 's gravity programmatically, in your code. That is, after setContentView() , use findViewById() to get the EditText , then call setGravity(Gravity. CENTER_HORIZONTAL) on it.

How do I get TextInputLayout from text?

Just use: TextInputLayout textInputLayout = findViewById(R. id. custom_end_icon); String text = textInputLayout.


1 Answers

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

like image 86
Gauthier Avatar answered Oct 05 '22 13:10

Gauthier