Android中EditText實(shí)現(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)容, 進(jìn)行復(fù)制.在早期的sdk, EditText有Editable屬性, 現(xiàn)在這個(gè)屬性已經(jīng)deprecated了.
解決方法:
其實(shí)只需一行代碼就能搞定et.setKeyListener(null);
注意, 這里不是setOnKeyListener, 而是setKeyListener. 此方法是TextView的成員, 調(diào)用后的效果完全符合預(yù)期, 并且獲得焦點(diǎn)后不會(huì)彈出輸入法.
下面是官方文檔的解釋
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進(jìn)行錄影的實(shí)例代碼
這篇文章主要介紹了Android中用MediaRecorder進(jìn)行錄影的實(shí)例代碼,有需要的朋友可以參考一下2014-01-01Android中Binder詳細(xì)學(xué)習(xí)心得
這篇文章主要介紹了Android中Binder詳細(xì)學(xué)習(xí)心得,并分析了Binder的詳細(xì)用法,需要的朋友參考下吧。2018-01-01Android快速實(shí)現(xiàn)發(fā)送郵件實(shí)例
本篇文章主要介紹了Android快速實(shí)現(xiàn)發(fā)送郵件實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04如何使用SurfaceView實(shí)現(xiàn)魚兒游動(dòng)動(dòng)畫
這篇文章主要教大家如何使用SurfaceView實(shí)現(xiàn)魚兒游動(dòng)動(dòng)畫,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04Android開發(fā)筆記 今天學(xué)到的一些屬性
離開實(shí)驗(yàn)室之前再貼上今天下午自己學(xué)到的一些基礎(chǔ)知識(shí) 上午干嘛了呢,忙著數(shù)據(jù)恢復(fù)呢2012-11-11Android?Studio打包?aar實(shí)現(xiàn)步驟示例詳解
這篇文章主要為大家介紹了Android?Studio打包aar步驟示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08