EditText上不可编辑 [英] EditText not editable
问题描述
我试图把的EditText与此code不可编辑:
I'm trying to put a EditText as not editable with this code:
<EditText android:id="@+id/outputResult"
android:inputType="text"
android:editable="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/result" />
我不得不添加此不编辑
I had to add this for not editable
android:focusable="false"
我是不是做错了什么?
Am I doing something wrong?
感谢您柠多少
推荐答案
机器人:编辑=假
应该工作,但是的it是德precated ,你应该使用的android:inputType下=无
代替。
android:editable="false"
should work, but it is deprecated, you should be using android:inputType="none"
instead.
另外,如果你想这样做在code,你可以这样做:
Alternatively, if you want to do it in the code you could do this :
EditText mEdit = (EditText) findViewById(R.id.yourid);
mEdit.setEnabled(false);
这也是一个可行的选择:
This is also a viable alternative :
EditText mEdit = (EditText) findViewById(R.id.yourid);
mEdit.setKeyListener(null);
如果你打算让你的的EditText
不可编辑,我建议使用的TextView
小部件,而不是的的EditText
,因为使用的EditText似乎在这种情况下,一种毫无意义的。
If you're going to make your EditText
non-editable, may I suggest using the TextView
widget instead of the EditText
, since using a EditText seems kind of pointless in that case.
编辑:改变的一些信息,因为我发现,的android:编辑
是pcated德$ P $
Altered some information since I've found that android:editable
is deprecated.
这篇关于EditText上不可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!