本文介绍了如何复制机器人:编辑="假"在code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在布局可以设置的EditText 插件是通过机器人不可编辑:可编辑的属性

In the layout you can set the EditText widget to be non-editable via the android:editable attribute.

我怎样才能做到这一点在code?我需要做的的EditText 控件可编辑取决于条件。

How can I do this in code? I need to make the EditText widget to be editable depending on conditions.

推荐答案

我觉得一个的是拒绝所有的变化是一个很好的解决方案:

I think an InputFilter that rejects all changes is a good solution:

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) : "";
        }
    }
});

编辑: dlazar建议(下)更改返回 dst.subSequence(DSTART,DEND)来克服的行为,消除的话。

dlazar suggested (below) to change the return to dst.subSequence(dstart, dend) to overcome behavior that removes words.

这篇关于如何复制机器人:编辑=&QUOT;假&QUOT;在code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:15