how to make hint disappear when edittext is touched?

后端 未结 12 1173
青春惊慌失措
青春惊慌失措 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 01:11

    Hint only disappears when you type in any text, not on focus. I don't think that there is any automatic way to do it, may be I am wrong. However, as a workaround I use the following code to remove hint on focus in EditText

    myEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus)
                myEditText.setHint("");
            else
                myEditText.setHint("Your hint");
        }
    });
    

提交回复
热议问题