Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發實例 >> Android中EditText實現不可編輯解決辦法

Android中EditText實現不可編輯解決辦法

編輯:Android開發實例

android:editable is deprecated: Use an <EditText> to make it editable
android:editable is deprecated: Use inputType instead

分析:關於EditText控件的read-only問題,即: 無法通過UI更改其中的內容, 但可以選定部分內容, 進行復制.在早期的sdk, EditText有Editable屬性, 現在這個屬性已經deprecated了.
 
解決方法:
其實只需一行代碼就能搞定et.setKeyListener(null);
注意, 這裡不是setOnKeyListener, 而是setKeyListener. 此方法是TextView的成員, 調用後的效果完全符合預期, 並且獲得焦點後不會彈出輸入法.
 
下面是官方文檔的解釋

Sets the key listener to be used with this TextView. This can be null to disallow user input. Note that this method has significant and subtle interactions with soft keyboards and other input method: see KeyListener.getContentType() for important details. Calling this method will replace the current content type of the text view with the content type returned by the key listener.
 
Be warned that if you want a TextView with a key listener or movement method not to be focusable, or if you want a TextView without a key listener or movement method to be focusable, you must call setFocusable again after calling this to get the focusability back the way you want it.

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved