在 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 中禁用滚动选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)