Search code examples
androidandroid-edittextandroid-textinputedittext

How to disappear the hint in TextInputEditText on receiving focus


I am using a TextInputEditText as suggested here to let the user add text up to a specific length.

However, I want that when the TextInputEditText view receives focus, the hint should disappear instead of going above the view, as shown in the aforementioned tutorial. In this answer, the solution described is for a EditText and it just makes the hint go transparent. However, for a TextInputEditText, even if I make the hint transparent on receiving focus, it will still occupy space above the view.

Is there a way to just remove it on receiving focus in the TextInputEditText, statically ? It is easy to do it through OnFocusChangeListener, but I was looking to do it at compile-time.


Solution

  • Try to set focus change listener on EditText and hide hint programmatically when focus is true and show again hint if focus is false and text is empty.