Android中EditText實現(xiàn)不可編輯解決辦法
android:editable is deprecated: Use an <EditText> to make it editable
android:editable is deprecated: Use inputType instead
分析:關(guān)于EditText控件的read-only問題,即: 無法通過UI更改其中的內(nèi)容, 但可以選定部分內(nèi)容, 進行復制.在早期的sdk, EditText有Editable屬性, 現(xiàn)在這個屬性已經(jīng)deprecated了.
解決方法:
其實只需一行代碼就能搞定et.setKeyListener(null);
注意, 這里不是setOnKeyListener, 而是setKeyListener. 此方法是TextView的成員, 調(diào)用后的效果完全符合預期, 并且獲得焦點后不會彈出輸入法.
下面是官方文檔的解釋
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.
相關(guān)文章
Android中用MediaRecorder進行錄影的實例代碼
這篇文章主要介紹了Android中用MediaRecorder進行錄影的實例代碼,有需要的朋友可以參考一下2014-01-01Android?Studio打包?aar實現(xiàn)步驟示例詳解
這篇文章主要為大家介紹了Android?Studio打包aar步驟示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08