如果你想消失在焦点上,试试这个:
textInputEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasfocus) {
if (hasfocus) {
textInputLayout.setHint("test");
} else {
textInputLayout.setHint(null);
}
}
});
如果您想在输入时消失(如果您正在寻找类似的东西),请尝试以下代码:
textInputEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (TextUtils.isEmpty(textInputEditText.getText().toString())) {
textInputLayout.setHint("test");
} else {
textInputLayout.setHint(null);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});