我编写了一个代码,我在Edittext中获得了大小斜体或下划线的跨距数。
现在我收到一个文本文件,其中包含以粗体字符写入的内容并使用BufferedReader
我获取该文件的内容。是否有可能在该文件上获得跨度?
这就是我在编辑文本中从字符串中获取跨度的方法。是否可以从SD卡上的文本文件中获取跨度?
Spannable ss = new SpannableString(text.getText()); // text is an EditText
if(text.getSelectionStart() - text.getSelectionEnd() == 0){
}
else{
int prologueStart=Integer.MAX_VALUE;
int epilogueEnd=-1;
for (UnderlineSpan span : getUnderlineSpans(ss, text.getSelectionStart(),text.getSelectionEnd())){
int spanStart=ss.getSpanStart(span);
if (spanStart < text.getSelectionStart()) {
prologueStart=Math.min(prologueStart, spanStart);
}
int spanEnd=ss.getSpanEnd(span);
if (spanEnd > text.getSelectionEnd()) {
epilogueEnd=Math.max(epilogueEnd, spanEnd);
}
ss.removeSpan(span);
}
if (prologueStart < Integer.MAX_VALUE) {
ss.setSpan(new UnderlineSpan(), prologueStart,
text.getSelectionStart(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (epilogueEnd > -1) {
ss.setSpan(new UnderlineSpan(), text.getSelectionEnd(), epilogueEnd,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
text.setText(ss);
text.setSelection(cursorPosition);
protected UnderlineSpan[] getUnderlineSpans(Spannable ss, int selectionStart,
int selectionEnd) {
return(ss.getSpans(selectionStart, selectionEnd, UnderlineSpan.class));
}