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
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…