how to make hint disappear when edittext is touched?

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

    This is my solution:

    final EditText editText = (EditText) findViewById(R.id.activity_edittext);
    editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                editText .setHint("my little hint");
            } else {
                editText .setHint("");
            }
        }
    });
    

提交回复
热议问题