Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
876 views
in Technique[技术] by (71.8m points)

android - Disable scroll option in 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

        }
    });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can try setMovementMethod() It will disable the EditText text scrolling. But you have to manage text size.

editText.setMovementMethod(null);

Hope it will help you...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...