您的位置:首页 > 其它

字符串拼接工具类

2015-12-13 22:16 399 查看
public class StringUtil {

/**
* 把str填充到上面的sourceID中的%1$s
* @param context
* @param textView
* @param sourceID String.xml里面的字符串,eg:name="weather_type"对应"天气状况:%1$s"
*                 就是这里的weather_type
* @param str 需要填充的字符串
*/
public static void setFormatText(Context context,TextView textView,int sourceID,String str){
String tipFormat = context.getResources().getString(sourceID);
textView.setText(String.format(tipFormat, str));
}

/**
* 使关键字高亮
* @param context
* @param textView
* @param complete 完整String串
* @param keyword 完整串中需要高亮的关键字
*/
public static void highNightKeyword(Context context ,TextView textView,String complete,String keyword){

int index =complete.indexOf(keyword);

SpannableStringBuilder builder = new SpannableStringBuilder(complete);
ForegroundColorSpan highLightSpan = new ForegroundColorSpan(context.getResources().getColor(R.color.navi_search_hightlight));

builder.se
8ed0
tSpan(highLightSpan, index, index + keyword.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(builder);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: