forked from AbrahamCaiJin/CommonUtilLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0275a72
commit ae1a709
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
CommonUtil/src/main/java/com/jingewenku/abrahamcaijin/commonutil/HtmlUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.jingewenku.abrahamcaijin.commonutil; | ||
|
||
/** | ||
* @Description:主要功能:html标签管理类 | ||
* @Prject: CommonUtilLibrary | ||
* @Package: com.jingewenku.abrahamcaijin.commonutil | ||
* @author: AbrahamCaiJin | ||
* @date: 2017年05月24日 18:15 | ||
* @Copyright: 个人版权所有 | ||
* @Company: | ||
* @version: 1.0.0 | ||
*/ | ||
|
||
public class HtmlUtils { | ||
/** | ||
* 为给定的字符串添加HTML红色标记,当使用Html.fromHtml()方式显示到TextView 的时候其将是红色的 | ||
* @param string 给定的字符串 | ||
* @return | ||
*/ | ||
public static String addHtmlRedFlag(String string){ | ||
return "<font color=\"red\">"+string+"</font>"; | ||
} | ||
|
||
/** | ||
* 将给定的字符串中所有给定的关键字标红 | ||
* @param sourceString 给定的字符串 | ||
* @param keyword 给定的关键字 | ||
* @return 返回的是带Html标签的字符串,在使用时要通过Html.fromHtml()转换为Spanned对象再传递给TextView对象 | ||
*/ | ||
public static String keywordMadeRed(String sourceString, String keyword){ | ||
String result = ""; | ||
if(sourceString != null && !"".equals(sourceString.trim())){ | ||
if(keyword != null && !"".equals(keyword.trim())){ | ||
result = sourceString.replaceAll(keyword, "<font color=\"red\">"+keyword+"</font>"); | ||
}else{ | ||
result = sourceString; | ||
} | ||
} | ||
return result; | ||
} | ||
} |