当前位置:操作系统 > 安卓/Android >>

android EditText获取光标位置并插入字符删除字符

1.获取光标位置
 
[java] 
int index = editText.getSelectionStart();  
 
int index = editText.getSelectionStart();
2.在光标处插入字符
 
[java] 
int index = editText.getSelectionStart();  
Editable editable = editText.getText();  
editable.insert(index, "aaaa");  
 
int index = editText.getSelectionStart();
Editable editable = editText.getText();
editable.insert(index, "aaaa");3.删除光标前字符
 
[java] 
int index = editText.getSelectionStart();  
Editable editable = editText.getText();  
editable.delete(index-1, index);  
 
int index = editText.getSelectionStart();
Editable editable = editText.getText();
editable.delete(index-1, index); 
 
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,