在 Android 中禁用 EditText

Disabling of EditText in Android(在 Android 中禁用 EditText)
本文介绍了在 Android 中禁用 EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在我的应用程序中,我有一个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)
How can i use MYSQL database connection in iphone application useing cocos2d?(如何在使用 cocos2d 的 iphone 应用程序中使用 MYSQL 数据库连接?)
Smoothly drag a Sprite in cocos2d - iPhone(在 cocos2d 中平滑拖动一个 Sprite - iPhone)
Cocos2D complex animations(Cocos2D 复杂动画)