Make EditText ReadOnly

前端 未结 22 1284

I want to make a read-only EditText view. The XML to do this code seems to be android:editable=\"false\", but I want to do this in code.

H

22条回答
  •  庸人自扰
    2020-12-04 19:15

    editText.setEnabled(false);
    editText.setFilters(new InputFilter[] { new InputFilter() {
        public CharSequence filter(CharSequence src, int start, int end,
                Spanned dst, int dstart, int dend) {
            return src.length() < 1 ? dst.subSequence(dstart, dend) : "";
        }
    } });
    

    This will give you uneditable EditText filter. you first need to put the text you want on the editText field and then apply this filter.

提交回复
热议问题