how to make hint disappear when edittext is touched?

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

    Here i have used the little bit of code to hide and show hint may be it'll be helpful.

    txt_username.setOnFocusChangeListener(new OnFocusChangeListener() {
    
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if(txt_username.getText().toString().isEmpty()){
                        if(hasFocus){
                            txt_username.setHint("");
                        }else{
                            txt_username.setHint(R.string.username);
                        }
                    }
                }
            });
    

提交回复
热议问题