Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep TextInputLayout always focused or keep label always expanded

Tags:

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?

like image 451
AndyRoid Avatar asked Jan 30 '16 02:01

AndyRoid


People also ask

How do I remove TextInputLayout error?

Now you can simply do input. setError(..) for new error and input. setErrorEnabled(false) to remove it.

What is the use of TextInputLayout in Android?

Layout which wraps a TextInputEditText , EditText , or descendant to show a floating label when the hint is hidden while the user inputs text.

How do I remove the default padding in TextInputLayout?

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.


2 Answers

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!

like image 192
Vesko Avatar answered Oct 18 '22 12:10

Vesko


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"               /> 
like image 23
Kaskasi Avatar answered Oct 18 '22 11:10

Kaskasi