手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android中EditText实现不可编辑解决办法
Android中EditText实现不可编辑解决办法
摘要:android:editableisdeprecated:Useantomakeiteditableandroid:editableisde...

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中EditText实现不可编辑解决办法】相关文章:

android自动化测试中实现长按并拖动

android Base64加密解密

android二级listview列表实现代码

Android 用SQLite实现事务的方法

android 实现圆角图片解决方案

Android HTTP 实现与服务器通信

Android控件系列之EditText使用方法

Android中使用pull解析器操作xml文件的解决办法

Android开发之SQLite的使用方法

解析在Android中为TextView增加自定义HTML标签的实现方法

精品推荐
分类导航