谁能告诉我如何使一个EditText不可编辑通过XML?我试着设置android:editable为false,但是

已弃用;而且 但是没有成功。


当前回答

试试这段代码。它在我的项目中工作,所以它将在你的项目中工作。

android:editable="false"

其他回答

我使用EditText.setFocusable(false),如果我想编辑,再次设置为true。

我试着这样做:

textView.setInputType( InputType.TYPE_NULL );

这应该有用,但对我来说没用。

我完成了下面的代码:

textView.setKeyListener(new NumberKeyListener() {
    public int getInputType() {
        return InputType.TYPE_NULL;
    }

    protected char[] getAcceptedChars() {
        return new char[] {};
    }
});

这很完美。

这样做的工作为我,我可以选择和复制到剪贴板,但我不能修改或粘贴。

android:enable="true"
android:textIsSelectable="true"
android:inputType="none"

只需使用android:enabled="false"即可。这也会给EditText一个外观,使它看起来不可编辑。

android:editable已弃用,请改用inputType。

   <EditText
        android:id="@+id/editText_x"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="70"
        android:inputType="none"
        android:hint="@string/enter_x" />