本文介紹了如何在 Android 中通過 XML 使 EditText 不可編輯?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
誰能告訴我如何使 EditText
不能通過 XML 編輯?我嘗試將 android:editable
設置為 false
,但是
Can anyone tell me how to make an EditText
not editable via XML? I tried setting android:editable
to false
, but
- 已棄用;和
- 沒用.
推薦答案
使用這個簡單的代碼:
textView.setKeyListener(null);
有效.
要稍后添加 KeyListener
,請執行以下操作
Edit : To add KeyListener
later, do following
1 : 將鍵監聽設置為 textView
1 : set key listener to tag of textView
textView.setTag(textView.getKeyListener());
textView.setKeyListener(null);
2 : 從標簽中獲取關鍵監聽器并將其設置回 textView
2 : get key listener from tag and set it back to textView
textView.setKeyListener((KeyListener) textView.getTag());
這篇關于如何在 Android 中通過 XML 使 EditText 不可編輯?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!