在 EditText 中禁用滚动选项

Disable scroll option in EditText(在 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.

editText.setMovementMethod(null);

editText.setMovementMethod(null);

希望对你有帮助...

这篇关于在 EditText 中禁用滚动选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 EditText 中禁用滚动选项

基础教程推荐