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>
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" .
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.
Just use: TextInputLayout textInputLayout = findViewById(R. id. custom_end_icon); String text = textInputLayout.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With