在我的应用程序中,我有一个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
EditText:禁用文本选择处理程序单击事件上的粘贴EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本选择处理程序单击事件上的粘贴/替换菜
2.3 上带有完成 SoftInput 操作标签的多行 EditTextMultiline EditText with Done SoftInput Action Label on 2.3(2.3 上带有完成 SoftInput 操作标签的多行 EditText)
如何在 Android 中检测向左或向右滑动?How to detect the swipe left or Right in Android?(如何在 Android 中检测向左或向右滑动?)
防止在Android中的屏幕旋转对话框解除Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋转对话框解除)
如何处理 ImeOptions 的完成按钮点击?How do I handle ImeOptions#39; done button click?(如何处理 ImeOptions 的完成按钮点击?)
您如何将 EditText 设置为仅接受 Android 中的数值How do you set EditText to only accept numeric values in Android?(您如何将 EditText 设置为仅接受 Android 中的数值?)