本文介绍了在EditText中禁用滚动选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户在EditText上输入更多字符时,禁用EditText中的滚动选项.除了滚动选项外,我还需要减小字体/类型大小.
Disable scroll option in EditText when the user enter more characters on that. Instead of scroll option i need to reduce the font/type size.
我当前正在做的是获取字符数,如果超过特定限制,则减小字体大小.我想做的是激活滚动选项时,需要减小尺寸.
What i am currently doing is getting the count of characters and if it is exceeding a particular limit reducing the font size. What i want to do is when the scrolling option getting activated, need to reduce the size.
qQuestionEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
qCount.setText(String.valueOf(200 - s.length()));
if (qQuestionEditText.length() > 180) {
qQuestionEditText.setTextSize(20);
} else if (qQuestionEditText.length() > 150) {
qQuestionEditText.setTextSize(22);
} else if (qQuestionEditText.length() > 120) {
qQuestionEditText.setTextSize(24);
} else if (qQuestionEditText.length() > 90) {
qQuestionEditText.setTextSize(26);
} else if (qQuestionEditText.length() > 60) {
qQuestionEditText.setTextSize(28);
} else if (qQuestionEditText.length() > 30) {
qQuestionEditText.setTextSize(30);
} else {
qQuestionEditText.setTextSize(32);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
推荐答案
您可以尝试 setMovementMethod(),它将禁用EditText文本滚动.但是您必须管理文本大小.
You can try setMovementMethod() It will disable the EditText text scrolling. But you have to manage text size.
希望它会帮助您...
Hope it will help you...
这篇关于在EditText中禁用滚动选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!