文字
恭喜y******x成功解冻红包,200元微信到账成功 恭喜x******9成功解冻红包,200元微信到账成功 恭喜j******4成功解冻红包,200元微信到账成功 恭喜5******n成功解冻红包,200元微信到账成功 恭喜9******s成功解冻红包,200元微信到账成功 恭喜a******2成功解冻红包,200元微信到账成功 恭喜3******4成功解冻红包,200元微信到账成功 恭喜c******w成功解冻红包,200元微信到账成功 恭喜0******k成功解冻红包,200元微信到账成功 恭喜7******6成功解冻红包,200元微信到账成功 恭喜4******j成功解冻红包,200元微信到账成功
代码
private void initMarquee() {if (this._TextViewMarquee != null) {StringBuilder sb = new StringBuilder();int count = 10;List<String> names = new ArrayList<>();for (int i = 0; i <= count; i++) {String name = DesensitizationUtils.getShowName(CommonUtil.genUid());names.add(name);sb.append(String.format("恭喜%s成功解冻红包,200元微信到账成功 ", name));}String text = sb.toString();SpannableString builder = new SpannableString(text);Log.e(TAG, "initMarquee: text: "+text );int latestIndex = 0;ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.parseColor("#ff241e"));int flag = SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE;for (int i = 0; i < names.size(); i++) {String name = names.get(i);int start = text.indexOf(name);int end = start + name.length();int start1 = text.indexOf("200元", latestIndex);int end1 = start1 + "200元".length();latestIndex = end1;builder.setSpan(CharacterStyle.wrap(foregroundColorSpan),start,end,flag);builder.setSpan(CharacterStyle.wrap(foregroundColorSpan),start1,end1,flag);}this._TextViewMarquee.setVisibility(View.VISIBLE);this._TextViewMarquee.setText(builder);
this._TextViewMarquee.setSelected(true);}}