android开发分享Android中EditText实现不可编辑解决办法

android:editable is deprecated: use an <edittext> to make it editable android:e

android:editable is deprecated: use an <edittext> to make it editable
android:editable is deprecated: use inputtype instead

上述就是android开发分享Android中EditText实现不可编辑解决办法的全部内容,如果对大家有所用处且需要了解更多关于Android学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

分析:关于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.

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/addevelopment/940649.html

(0)
上一篇 2021年11月13日
下一篇 2021年11月13日

精彩推荐