Android中EditText实现不可编辑解决办法
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.
相关文章
android FM播放时拔出耳机后FM APP自动close解决方法
android FM播放时拔出耳机后FM APP自动close关闭的情况应该怎样解决呢?下面为大家详细介绍下具体修改方法,感兴趣的朋友可以参考下2013-06-06
Android即时通讯设计(腾讯IM接入和WebSocket接入)
本文主要介绍了Android即时通讯设计(腾讯IM接入和WebSocket接入),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2022-04-04
解决Android studio 2.3升级到Android studio 3.0 后apt报错问题
原来项目在Android studio 2.3一切正常,升级到了3.0之后报错,不支持apt了,其实解决这个问题很简单,只需要修改两点内容就可以,下面脚本之家小编带领大家通过本文学习吧2017-12-12
Android RecyclerView添加头部和底部实例详解
这篇文章主要介绍了Android RecyclerView添加头部和底部实例详解的相关资料,需要的朋友可以参考下2017-06-06


最新评论