【发布时间】:2019-04-06 06:53:39
【问题描述】:
我想实现If 和Else 条件来检查所选文本是否突出显示。我可以突出显示文本,但不知道要再次删除突出显示文本的if() 条件。我搜索了很多,但没有得到明确的答案。这是我的代码:
private void highlightTextCondition() {
int selectionStart = bodyText.getSelectionStart();
int selectionEnd = bodyText.getSelectionEnd();
if (selectionStart > selectionEnd) {
int temp = selectionEnd;
selectionEnd = selectionStart;
selectionStart = temp;
}
if (selectionEnd > selectionStart) {
Spannable str = bodyText.getText();
boolean exists = false;
for (int i = 0; i < str.length(); i++) {
if (**want this statement here for highlight texted**) {
str.removeSpan(*****);
exists = false;
}
}
if (!exists) {
str.setSpan(new BackgroundColorSpan(Color.YELLOW), selectionStart, selectionEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
exists = true;
}
bodyText.setSelection(selectionStart, selectionEnd);
}
}
【问题讨论】:
标签: javascript java android eclipse