Android set TextView highlight font, font color gradient
Gradient rendering:
Implemented tools TextFontUtils
:
public class TextFontUtils {
public static String HIGHLIGHT_COLOR = "#0fc264";
public static void setHighlightFont(String regexStr, String targetStr, TextView textView) {
targetStr = targetStr.replaceAll(regexStr, "<font color='" + HIGHLIGHT_COLOR + "'>" + regexStr + "</font>");
textView.setText(Html.fromHtml(targetStr));
}
public static void setGradientFont(TextView textView, String startColor, String endColor){
LinearGradient gradient = new LinearGradient(0, 0, 0,
textView.getPaint().getTextSize(),
Color.parseColor(startColor), Color.parseColor(endColor),
Shader.TileMode.CLAMP);
textView.getPaint().setShader(gradient);
textView.invalidate();
}
}