public static CharSequence setColor(Context context, String text, String text1, String text2) {
SpannableStringBuilder style = new SpannableStringBuilder(text);
// 关键字“孤舟”变色,0-text1.length()
style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorPrimary)), 0, text1.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// 关键字“寒江雪”变色,text1.length() + 6-text1.length() + 6 + text2.length()
style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorAccent)), text1.length() + 6, text1.length() + 6 + text2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return style;
}
public static CharSequence matcherSearchText(int color, String string, String keyWord) {
SpannableStringBuilder builder = new SpannableStringBuilder(string);
int indexOf = string.indexOf(keyWord);
if (indexOf != -1) {
builder.setSpan(new ForegroundColorSpan(color), indexOf, indexOf + keyWord.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
}
return builder;
}
public static SpannableString matcherSearchText(int color, String text, String keyword) {
SpannableString ss = new SpannableString(text);
Pattern pattern = Pattern.compile(keyword);
Matcher matcher = pattern.matcher(ss);
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
ss.setSpan(new ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return ss;
}
public static SpannableString matcherSearchTitle(int color, String text, String keyword) {
String string = text.toLowerCase();
String key = keyword.toLowerCase();
Pattern pattern = Pattern.compile(key);
Matcher matcher = pattern.matcher(string);
SpannableString ss = new SpannableString(text);
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
ss.setSpan(new ForegroundColorSpan(color), start, end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return ss;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有