简体   繁体   English

android setEnabled但未更改文本

[英]android setEnabled but unchange text

I have some edit text fields which I would like to make un-editable at certain times. 我有一些编辑文本字段,希望在某些时候使其不可编辑。 I have used the setEnabled method but that also grays out the text. 我已经使用了setEnabled方法,但是也使文本变灰。 Is there a way to toggle whether the field can be edited but not change the appearance of the text? 有没有一种方法可以切换是否可以编辑字段但不能更改文本的外观? It has been a little while since I last messed with Android but I think I used to be able to use setEditable which did exactly what I am looking for. 自从我上次接触Android以来已经有一段时间了,但是我认为我曾经能够使用setEditable来实现我想要的功能。

I have tried to use the android:focusable="false" but I am still able to edit the field, unless that is only the behavior of the emulator I don't think that will work. 我尝试使用android:focusable =“ false”,但我仍然可以编辑该字段,除非那只是模拟器的行为,我认为这行不通。

You can disable input for an EditText without any visible indication by setting it's input type to InputType.TYPE_NULL . 您可以通过将EditText的输入类型设置为InputType.TYPE_NULL来禁用EditText的输入,而无需任何可见的指示。 An example would look like: 一个例子如下:

import android.text.InputType;
. . .
myEditText..setInputType(InputType.TYPE_NULL);

Note that this behavior doesn't exactly jive with what the reference docs seem to be saying and that there doesn't appear to be an XML equivalent. 请注意,此行为与参考文档中所说的并不完全一致,并且似乎没有XML等效项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM