File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
CommonUtil/src/main/java/com/jingewenku/abrahamcaijin/commonutil Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .jingewenku .abrahamcaijin .commonutil ;
2
+
3
+ /**
4
+ * @Description:主要功能:html标签管理类
5
+ * @Prject: CommonUtilLibrary
6
+ * @Package: com.jingewenku.abrahamcaijin.commonutil
7
+ * @author: AbrahamCaiJin
8
+ * @date: 2017年05月24日 18:15
9
+ * @Copyright: 个人版权所有
10
+ * @Company:
11
+ * @version: 1.0.0
12
+ */
13
+
14
+ public class HtmlUtils {
15
+ /**
16
+ * 为给定的字符串添加HTML红色标记,当使用Html.fromHtml()方式显示到TextView 的时候其将是红色的
17
+ * @param string 给定的字符串
18
+ * @return
19
+ */
20
+ public static String addHtmlRedFlag (String string ){
21
+ return "<font color=\" red\" >" +string +"</font>" ;
22
+ }
23
+
24
+ /**
25
+ * 将给定的字符串中所有给定的关键字标红
26
+ * @param sourceString 给定的字符串
27
+ * @param keyword 给定的关键字
28
+ * @return 返回的是带Html标签的字符串,在使用时要通过Html.fromHtml()转换为Spanned对象再传递给TextView对象
29
+ */
30
+ public static String keywordMadeRed (String sourceString , String keyword ){
31
+ String result = "" ;
32
+ if (sourceString != null && !"" .equals (sourceString .trim ())){
33
+ if (keyword != null && !"" .equals (keyword .trim ())){
34
+ result = sourceString .replaceAll (keyword , "<font color=\" red\" >" +keyword +"</font>" );
35
+ }else {
36
+ result = sourceString ;
37
+ }
38
+ }
39
+ return result ;
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments