谁能告诉我如何使一个EditText不可编辑通过XML?我试着设置android:editable为false,但是
已弃用;而且 但是没有成功。
谁能告诉我如何使一个EditText不可编辑通过XML?我试着设置android:editable为false,但是
已弃用;而且 但是没有成功。
当前回答
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" />
其他回答
请试试这个!,它可能会帮助一些人
<EditText
android:enabled="false"
android:textColor="#000000"/>
如果你想点击它,但不想编辑它,试试:
android:focusable="false"
<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);
试试这段代码。它在我的项目中工作,所以它将在你的项目中工作。
android:editable="false"
正如你提到的,android:editable已被弃用。android:inputType="none"应该被用来代替,但它不工作,由于一个bug (https://code.google.com/p/android/issues/detail?id=2854)
但是你可以通过使用focusable来达到同样的效果。
通过XML:
<EditText ...
android:focusable="false"
</EditText>
从代码:
((EditText) findViewById(R.id.LoginNameEditText)).setFocusable(false);