EditText设置/隐藏光标位置、选中文本和获取/清除焦点
来源:互联网 发布:office 2013 优化版 编辑:程序博客网 时间:2024/06/16 13:30
http://orgcent.com/android-edittext-cursor-position-focus/ | 萝卜白菜的博客
有时候需要让光标显示在EditText的指定位置或者选中某些文本。同样,为了方便用户输入以提升用户体验,可能需要使EditText获得或失去焦点。
1. 设置光标到指定位置
1
2
2
EditText et = (EditText) findViewById(R.id.etTest);
et.setSelection(2);
et.setSelection(2);
PS:当内容过多时,可通过设置光标位置来让该位置的内容显示在屏幕上。
2. 隐藏光标
1
2
3
2
3
EditText et = (EditText) findViewById(R.id.etTest);
//设置光标不显示,但不能设置光标颜色
et.setCursorVisible(false);
//设置光标不显示,但不能设置光标颜色
et.setCursorVisible(false);
3. 获得焦点时全选文本
1
2
2
EditText et = (EditText) findViewById(R.id.etTest);
et.setSelectAllOnFocus(true);
et.setSelectAllOnFocus(true);
PS:此方法可用来在用户点击EditText时,选中默认内容。
4. 获取和失去焦点
1
2
3
2
3
EditText et = (EditText) findViewById(R.id.etTest);
et.requestFocus();//请求获取焦点
et.clearFocus();//清除焦点
et.requestFocus();//请求获取焦点
et.clearFocus();//清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- [Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- [Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- [Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- Android - 小功能 - EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- Android--Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- Android开发中EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- EditText光标位置的控制或选中某些文本
- EditText获取光标位置
- 设置EditText光标位置
- 设置EditText光标位置
- MFC项目开发方法和技巧总结(适合初级编程人员)
- IOS开发之触摸与点击事件:UITapGestureRecognizer应用
- Mac下eclipse配置SVN
- 串口 驱动 MFC DLL 相关文章记录
- Google Analytics跨域跟踪的实现方法
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点
- 勾股定理证明
- php是什么?
- MFC操作——设置静态文本 大小 字体格式 颜色
- 利用NativeWindow监视WndProc消息
- 那些年,我们一起学过的R语言
- log4 net
- Shell 学习(一、编写shell脚本和执行)
- 3-5年的漫长寒冬 小微企业如何过?