TextView 选择文字
Posted lucktian
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TextView 选择文字相关的知识,希望对你有一定的参考价值。
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;
}
});
以上是关于TextView 选择文字的主要内容,如果未能解决你的问题,请参考以下文章