英文:
how to highlight search result in editText, without losing break lines
问题
我希望你一切安好。
尝试了许多代码后,只有一个代码对我百分百有效,但结果显示时没有换行,这是代码(来自这里):
String textToHighlight = edittext2.getText().toString();
String oldString = edittext1.getText().toString();
String newString = oldString.replaceAll(textToHighlight, "<span style='background-color: RED'>" + textToHighlight + "</span>");
textview1.setText(Html.fromHtml(newString));
这是oldString
的屏幕截图:
这是newString
的屏幕截图:
我希望能够在保留原始文本的换行的情况下获得突出显示搜索词的结果。非常感谢你的帮助。提前致谢。
英文:
i hope you are fine.
after trying many codes, just one worked 100% for me, but the result appear without break lines, this is the code (taken from here) :
String textToHighlight = edittext2.getText().toString();
String oldString = edittext1.getText().toString();
String newString = oldString.replaceAll(textToHighlight, "<span
style='background-color: RED'>"+textToHighlight+"</span>");
textview1.setText(Html.fromHtml(newString));
and this is screenshot for the oldString :
and this is screenshot of restlt(newString):
i want to get result with highlight searched words without losing break lines of original text.
i hope you help and thanks in advance
答案1
得分: 0
在您的</span>
闭合标签之后添加<br>
HTML标签。
英文:
add <br>
HTML tag in the end after your's </span>
closing tag
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论