GIFT: TextInputEditText nested in TextInputLayout !
TL DR!: Use this Kotlin extension feature
fun EditText.setHintAndLabel( textInputLayout: TextInputLayout, label: String?, // hint in the TextInputLayout hint: String? // hint in the EditText ) { this.hint = "" textInputLayout.hint = label this.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus -> if (hasFocus) { this.hint = hint ?: "" } else { this.hint = "" } } }
What is the problem and how to solve it?
The problem is that the EditText tooltip overlaps if there is a tooltip in the TextInputLayout . Which show in this case? Good question: we want the EditText tooltip to appear only when it is in the TextInputLayout / cursor is inside, and the TextInputLayout tooltip should always be displayed.
โฎ Thus, we set the tooltip for EditText when it has focus, and delete it as soon as it loses focus. ๐
source share