How to disable floating-point animation when filling in EditText fields wrapped in TextInputLayout

I would like to have a floating label already in place when I pre-populate the EditText field. When the view loads, the tooltip is still displayed behind the text before it is animated on the floating label. There seems to be no method in the TextInputLayout library support method. Any thoughts?

+5
source share
2 answers

In the v23 support design library, you can use:

til.setHintAnimationEnabled(false); 

Here you can find javadoc .

+8
source

Based on Gabriels answer, I wrote a small method to run after loading the hierarchy of views, which disables the animation on initial display, but allows it after the guardians. Add this to your base activity / snippet / view and this will solve the problem.

 private void setTextInputLayoutAnimation(View view) { if (view instanceof TextInputLayout) { TextInputLayout til = (TextInputLayout) view; til.setHintAnimationEnabled(false); til.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { til.getViewTreeObserver().removeOnPreDrawListener(this); til.setHintAnimationEnabled(true); return false; } }); return; } if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; for (int i = 0; i < group.getChildCount(); i++) { View child = group.getChildAt(i); setTextInputLayoutAnimation(child); } } } 
0
source

All Articles