[
如果我使用单一类型的字体,其工作精细文本不会从边缘切割。但是当我尝试使用具有不同文本样式的两种不同字体时,则从Textview中的边缘切割文本。
Typeface tfNormal = Typeface.createFromAsset(ctx.getAssets(), "fonts/futura_tee.ttf");
Typeface tfBold = Typeface.createFromAsset(ctx.getAssets(), "fonts/futura_tee_bold.ttf");
String msg="tournament sopan 20 nov offline double 2 was updated";
SpannableStringBuilder sb = new SpannableStringBuilder();
final String t_name = "sopan 20 nov offline double 2";
int startindex = msg.indexOf(t_name);
int endindex = startindex + t_name.length();
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
//some click event
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setUnderlineText(false);
ds.setColor(ctx.getResources().getColor(R.color.blue_color));
ds.setTypeface(tfBold);
}
};
if (startindex >= 0) {
sb.setSpan(clickableSpan, startindex , endindex , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
}
textview.setMovementMethod(LinkMovementMethod.getInstance());
textview.setText(sb, TextView.BufferType.SPANNABLE);
textview.setTypeface(tfNormal);