問題描述
在我的應用程序中,我有一個 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模板網!