TextView 选择文字
2016-05-23 17:59
417 查看
final CharSequence edit = text2.getText();
text2.setCursorVisible(true);
text2.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
int sta = 0;
int end = 0;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
sta = text2.getSelectionStart();
return true;
}
case MotionEvent.ACTION_MOVE: {
text2.setTextColor(Color.RED);
SpannableStringBuilder styled = new SpannableStringBuilder(edit);
styled.setSpan(new ForegroundColorSpan(Color.BLUE), 1,30,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text2.setText(styled);
return true;
}
case MotionEvent.ACTION_UP: {
end = text2.getSelectionEnd();
CharSequence sel = edit.subSequence(5, 80);
text1.append(String.valueOf(end));
return true;
}
}
return true;
}
});
text2.setCursorVisible(true);
text2.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
int sta = 0;
int end = 0;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
sta = text2.getSelectionStart();
return true;
}
case MotionEvent.ACTION_MOVE: {
text2.setTextColor(Color.RED);
SpannableStringBuilder styled = new SpannableStringBuilder(edit);
styled.setSpan(new ForegroundColorSpan(Color.BLUE), 1,30,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text2.setText(styled);
return true;
}
case MotionEvent.ACTION_UP: {
end = text2.getSelectionEnd();
CharSequence sel = edit.subSequence(5, 80);
text1.append(String.valueOf(end));
return true;
}
}
return true;
}
});
相关文章推荐
- memcpy函数更自己的实现
- .Net 内存溢出(System.OutOfMemoryException)的常见情况和处理方式总结
- 架构漫谈(三):如何做好架构之识别问题
- MongoDB: 数据库复制
- Spark中组件Mllib的学习12之密集向量和稀疏向量的生成
- Excel如何批量删除数字单元格前的撇号
- 走马观花: Linux 系统调用 open 七日游(三)
- mongoDB索引
- 单例模式的优缺点
- Android 图片缓存之内存缓存技术LruCache,软引用
- LeetCode 112. Path Sum
- DOM
- 深入理解移动端touch事件
- http://www.cnblogs.com/iamlilinfeng/archive/2012/09/25/2700049.html
- js parseInt函数
- 走马观花: Linux 系统调用 open 七日游(二)
- LeetCode OJ 31. Next Permutation
- (转)如何在JavaScript与ActiveX之间传递数据3
- windows 中使用hbase 异常:java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
- 创建交互式shell脚本对话框