在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)