I would like to be able to have the floating label already in place when I pre-populate the EditText field. When the view loads, the hint is still displayed behind the text before it is animated to the floating label. There doesn't seem to be a method for this in Support Library's TextInputLayout. Any thoughts?
Asked
Active
Viewed 6,825 times
3 Answers
9
With the support design library v23 you can use:
til.setHintAnimationEnabled(false);
Here you can find the javadoc.

Gabriele Mariotti
- 320,139
- 94
- 887
- 841
-
2One note, the animation need to be turned off before we set the text/hint. Having the sequence wrong would not turn off the animation. – Elye Aug 01 '16 at 01:20
-
Working. Make sure that you call the method on your `TextInputEditText` and not `TextINputLayout`. The animation is played, after you set the fields, and then enable the animation again though. :-(( – Sevastyan Savanyuk Nov 09 '17 at 09:35
-
1@Sevastyan You don't really need the animation until the field is cleared. Add a text change listener and re-enable animations when the field's character count reaches 0. – Rene Juuse Nov 10 '17 at 16:10
3
Based Gabriels answer I wrote a small method to run after loading the view hierarchy that disables animation on initial display but enables it after wards. Add this to your Base Activity/Fragment/View and it will solve it issue.
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);
}
}
}

EE66
- 4,601
- 1
- 17
- 20
0
I got solution using below code, i tried using xml but not working longer, you can try as to set hint programatically to both TextInputLayout and TextInputEditText
TextInputLayout hintView = (TextInputLayout) findViewById(R.id.activity_login_inputlayout_password);
hintView.setHintAnimationEnabled(false);
hintView.setHint("");
yourEditTextPassword.setHint(getString(R.string.text_password_hint));

varotariya vajsi
- 3,965
- 37
- 39