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

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


当前回答

请试试这个!,它可能会帮助一些人

<EditText  
android:enabled="false"
android:textColor="#000000"/>

其他回答

这个组合对我很有效:

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

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

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

android:editable="false"

如果你想在java代码中这样做,只需使用这一行来禁用它:

editText.setEnabled(false);

这是为了启用它:

editText.setEnabled(true);
<EditText
    android:id="@+id/txtDate"
    android:layout_width="140dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="2dp"
    android:clickable="false"
    android:cursorVisible="false"
    android:gravity="center" />

并使用以下:

txtDate.setKeyListener(null);