Why can I type into a disabled EditText?

后端 未结 8 1624
时光取名叫无心
时光取名叫无心 2021-01-11 19:52

If I disable an EditText widget using

editText.setEnabled(false);

I can still type into it using the on-screen input method (in

相关标签:
8条回答
  • 2021-01-11 20:10

    I notice that you can't activate the on-screen keyboard by tapping on a disabled EditText, and also the DEL key doesn't work, so this looks like a bug to me. I filed it as issue 2771 in the Android issue tracker.

    0 讨论(0)
  • 2021-01-11 20:12
    etComment.setEnabled(flag);
    etComment.setFocusable(flag);
    etComment.setFocusableInTouchMode(flag);
    if (flag) {
        etComment.requestFocus();
    }
    etComment.setFilters(new InputFilter[] { new InputFilter() {
        @Override
        public CharSequence filter(
            CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                if (!flag) {
                    return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                }
                return null;
            }
        }
    });
    

    for all you can got it!

    0 讨论(0)
  • 2021-01-11 20:12

    I think you should be able to editText.setOnClickListener() with your own function and call super.onClickListener() if you want your text edited.

    Edit:
    Following link has some answers which sound more like the right way:
    Can we have uneditable text in edittext

    0 讨论(0)
  • 2021-01-11 20:16

    Perhaps You could alternatively dynamically substitute with TextView and back. But You would probably need to adjust font to match the EditText.

    0 讨论(0)
  • 2021-01-11 20:22

    I fixed this issue but the patch only got included in Honeycomb. That's why I've created a little project which will contain my backported fixes to versions starting from 2.1. It contains the fix for bug 2771: http://code.google.com/p/android-fixes/
    You can check out the "library" from the svn and include it in your project. Then instead of android.widget.EditText import edu.ubbdroid.android.widget.EditText (which extends the original EditText) and the problem should be gone :)

    0 讨论(0)
  • 2021-01-11 20:27
    edittext.setKeyListener(null);
    

    This will help you

    0 讨论(0)
提交回复
热议问题