如何禁用光标定位和文本选择在一个EditText? (安卓)光标、文本、EditText

由网友(请叫我小祸害)分享简介:我在寻找一种方式来prevent从任何地方移动光标位置的用户。光标应该始终保持在当前的EditText值的末尾。除了该用户不应该能够以选择的EditText任何东西。你有什么想法如何用一个EditText认识到,在Android的?I'm searching for a way to prevent the user...

我在寻找一种方式来prevent从任何地方移动光标位置的用户。光标应该始终保持在当前的EditText值的末尾。除了该用户不应该能够以选择的EditText任何东西。你有什么想法如何用一个EditText认识到,在Android的?

I'm searching for a way to prevent the user from moving the cursor position anywhere. The cursor should always stay at the end of the current EditText value. In addition to that the user should not be able to select anything in the EditText. Do you have any idea how to realize that in Android using an EditText?

要澄清:用户应能够插入文字,但只有在末端

To clarify: the user should be able to insert text, but only at the end.

推荐答案

我有同样的问题。这结束了工作对我来说:

I had the same problem. This ended up working for me:

public class CustomEditText extends EditText {

    @Override
    public void onSelectionChanged(int start, int end) {

        CharSequence text = getText();
        if (text != null) {
            if (start != text.length() || end != text.length()) {
                setSelection(text.length(), text.length());
                return;
            }
        }

        super.onSelectionChanged(start, end);
    }

}
阅读全文

相关推荐

最新文章