删除线样式。
示例1:
StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(strikethroughSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);
示例2:
Parcel parcel = Parcel.obtain();
StrikethroughSpan strikethroughSpan = new StrikethroughSpan(parcel);
String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(strikethroughSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);
示例3:
重写updateDrawState(TextPaint textPaint)
方法,修改删除线的样式、文本颜色:
StrikethroughSpan strikethroughSpan = new StrikethroughSpan() {
@Override
public void updateDrawState(TextPaint textPaint) {
textPaint.setColor(Color.argb(255, 54, 92, 124));
textPaint.setStrikeThruText(true);
}
};
String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(strikethroughSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);