Stack Overflow Asked by Rajan Prasad on January 14, 2021
I am using a TextInputEditText
as suggested here to let the user add text up to a specific length.
However, I want that when the TextInputEditText
view receives focus, the hint should disappear instead of going above the view, as shown in the aforementioned tutorial. In this answer, the solution described is for a EditText
and it just makes the hint go transparent. However, for a TextInputEditText
, even if I make the hint transparent on receiving focus, it will still occupy space above the view.
Is there a way to just remove it on receiving focus in the TextInputEditText
, statically ? It is easy to do it through OnFocusChangeListener
, but I was looking to do it at compile-time.
Try to set focus change listener on EditText and hide hint programmatically when focus is true and show again hint if focus is false and text is empty.
Correct answer by DennyDog on January 14, 2021
Simply add:-
try this from the following post how to make hint disappear when edittext is touched?
edittxt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus)
edittxt.setHint("");
else
edittxt.setHint("hint");
}
});
Answered by Riaz Ali Khan on January 14, 2021
try to set EditText hint in java and it will automatically hide when you click on the EditText.
edtPassword.setHint(getString(R.string.YOUR_HINT));
Answered by Rajneesh Kumar on January 14, 2021
Try this if you want to disappear on focus:
textInputEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasfocus) {
if (hasfocus) {
textInputLayout.setHint("test");
} else {
textInputLayout.setHint(null);
}
}
});
Try below code if you want to disappear on typing (in case you are looking for something like this):
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) {
}
});
Answered by Vijay on January 14, 2021
try this from the following post how to make hint disappear when edittext is touched?
myEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus)
myEditText.setHint("");
else
myEditText.setHint("Your hint");
}
});
Answered by Joaquín on January 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP