当前位置: 移动技术网 > IT编程>移动开发>Android > Android中EditText实现不可编辑解决办法

Android中EditText实现不可编辑解决办法

2019年07月24日  | 移动技术网IT编程  | 我要评论

花样奇案,豪情 淮山杞子,少年阿宾12

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.

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网