下角标样式。
示例1:
SubscriptSpan subscriptSpan = new SubscriptSpan();
String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(subscriptSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);
示例2:
Parcel parcel = Parcel.obtain();
SubscriptSpan subscriptSpan = new SubscriptSpan(parcel);
String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(subscriptSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);
示例3:
重写updateDrawState(TextPaint textPaint)
方法,修改文本样式:
SubscriptSpan subscriptSpan = new SubscriptSpan() {
@Override
public void updateDrawState(TextPaint textPaint) {
super.updateDrawState(textPaint);
textPaint.setColor(Color.argb(255, 54, 92, 124));
}
};
String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(subscriptSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);