绝对尺寸大小的样式。
AbsoluteSizeSpan(int size):参数size,以size的指定的像素值来设定文本大小。
AbsoluteSizeSpan(int size, boolean dip):参数size,以size的指定像素值来设定文本大小, 如果参数dip为true则以size指定的dip为值来设定文本大小。
AbsoluteSizeSpan(Parcel src):参数src,包含有size和dip值的包装类。
示例1:
AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(18);
//AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(18, true);
String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(absoluteSizeSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);
示例2:
Parcel parcel = Parcel.obtain();
parcel.writeInt(29);//字体大小
parcel.writeInt(8);//是否是dip单位
parcel.setDataPosition(0);
AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(parcel);
String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(absoluteSizeSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);
示例3:
重写updateDrawState(TextPaint textPaint)
方法,修改删除线的样式、文本颜色:
AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(18) {
@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(absoluteSizeSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);