如何以编程方式在 edittext 中启用建议?
How to enable suggestions in an edittext programmatically?
我使用
在达到特定字符限制时禁用了 EditText 上的建议
mEditQuestionBox.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
但是,如果用户要按退格键并再次键入,我需要返回建议功能。有帮助吗?
本质上归结为这个。是否有可用于再次启用建议的 InputType?如果没有,谁能想到解决方法?
根据需要在 EditText 的 addTextChangeListener 中实现 onTextChanged()。
mEditQuestionBox.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length()< threshold){
mEditQuestionBox.setInputType(InputType. TYPE_CLASS_TEXT);
}
if(s.length()>= threshold){
mEditQuestionBox.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
我使用
在达到特定字符限制时禁用了 EditText 上的建议mEditQuestionBox.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
但是,如果用户要按退格键并再次键入,我需要返回建议功能。有帮助吗?
本质上归结为这个。是否有可用于再次启用建议的 InputType?如果没有,谁能想到解决方法?
根据需要在 EditText 的 addTextChangeListener 中实现 onTextChanged()。
mEditQuestionBox.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length()< threshold){
mEditQuestionBox.setInputType(InputType. TYPE_CLASS_TEXT);
}
if(s.length()>= threshold){
mEditQuestionBox.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});