how to make hint disappear when edittext is touched?

后端 未结 12 1145
青春惊慌失措
青春惊慌失措 2020-12-14 00:39

In my application in android are many EditText fields. And I ran into a problem with hint. It is not disappearing when EditText is focused, but it disappears when I start to

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 00:55

    My solution is like this. It shows hint when empty and not focused and hides if there is text or if it is touched

    fun hideHint() {
            tilFloating.isHintAnimationEnabled = false
            etFloating.onFocusChangeListener = OnFocusChangeListener { v, hasFocus ->
                if ((etFloating.text != null && etFloating.text.toString() != "") || hasFocus)
                    tilFloating.hint = ""
                else
                    tilFloating.hint = mHint
            }
        }
    

提交回复
热议问题