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

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


当前回答

正如在其他回答中提到的,您可以执行setEnabled(false),但由于您正在询问如何通过XML设置它,下面是如何做到这一点。

将以下属性添加到您的EditText:

android:enabled="false"

其他回答

正如在其他回答中提到的,您可以执行setEnabled(false),但由于您正在询问如何通过XML设置它,下面是如何做到这一点。

将以下属性添加到您的EditText:

android:enabled="false"

他们弃用了“可编辑的”,但没有在inputType中提供相应的工作。

顺便说一下,inputType="none"有什么影响吗?在我看来,用不用它没有任何区别。

例如,默认的editText是单行的。但是您必须选择一个inputType,使其为单行。如果你选择“none”,它仍然是多行。

这个组合对我很有效:

<EditText ... >
    android:longClickable="false"
    android:cursorVisible="false"
    android:focusableInTouchMode="false"
</EditText>

我试着这样做:

textView.setInputType( InputType.TYPE_NULL );

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

我完成了下面的代码:

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

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

这很完美。

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" />