在我的应用程序中,我有一个 EditText,用户只有读取权限而不是写入权限.
In my application, I have an EditText that the user only has Read access not Write access.
在代码中我设置了 android:enabled="false"
.
虽然EditText的背景变暗了,但是当我点击它时,键盘会弹出,我可以改变文字.
Although the background of EditText changed to dark, when I click on it the keyboard pops up and I can change the text.
我应该设置什么来禁用 EditText?
What should I set to disable EditText?
我相信正确的应该是设置 android:editable="false"
.
I believe the correct would be to set android:editable="false"
.
如果你想知道为什么我的链接指向 TextView
的属性,你的答案是因为 EditText
继承自 TextView
:
And if you wonder why my link point to the attributes of TextView
, you the answer is because EditText
inherits from TextView
:
EditText 是一层薄薄的外衣将自身配置为的 TextView可编辑.
EditText is a thin veneer over TextView that configures itself to be editable.
更新:
正如下面评论中提到的,editable
已被弃用(从 API 级别 3 开始).您应该改用 inputType
(值为 none
).
Update:
As mentioned in the comments below, editable
is deprecated (since API level 3). You should instead be using inputType
(with the value none
).
这篇关于在 Android 中禁用 EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!