I was wondering if it's possible to always keep the label expanded regardless of whether or not there is text in the EditText
. I looked around in the source and it is a using a ValueAnimator
and a counter
inside a TextWatcher
to animate or not animate changes. Maybe I can set a custom TextWatcher
with a custom ValueAnimator
on the EditText
inside the TextInputLayout
?
Now you can simply do input. setError(..) for new error and input. setErrorEnabled(false) to remove it.
Layout which wraps a TextInputEditText , EditText , or descendant to show a floating label when the hint is hidden while the user inputs text.
You can just set the start and end padding on the inner EditText to 0dp. Here's a screenshot with Show Layout Bounds turned on so you can see that the hints go all the way to the edge of the view.
The current version of the TextInputLayout
exists specifically to do one thing - show / hide the helper label depending on whether there's some text in the EditText
or not. What you want is different behaviour, so you need a different widget than the TextInputLayout
. This case is the perfect candidate to writing a custom view that will suit your needs.
That said, your idea of setting a custom TextWatcher
to the EditText
won't work either because TextInputLayout
doesn't expose anything of it's internals that actually handle the animations - neither updateLabelVisibility()
, setEditText()
, the magic Handler
that does the work or anything else. Of course we surely don't want to go the reflection path for a detail like this, so...
Just use MaterialEditText! It has the following property that does exactly what you want.
met_floatingLabelAlwaysShown: Always show the floating label, instead of animating it in/out. False as default.
The library is quite stable (I'm using it in two different projects myself) and has plenty of options to customise. Hope it helps!
For me with support design 23.3.0 it works to use
<android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="wow such hint" app:hintEnabled="true" app:hintAnimationEnabled="false" />
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