I have a custom class as follows:
public class CustomTypefaceSpan extends TypefaceSpan {
private final Typeface newType;
public CustomTypefaceSpan(String family, Typeface type) {
super(family);
newType = type;
}
@Override
public void updateDrawState(TextPaint ds) {
applyCustomTypeFace(ds, newType);
}
@Override
public void updateMeasureState(TextPaint paint) {
applyCustomTypeFace(paint, newType);
}
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
int oldStyle;
Typeface old = paint.getTypeface();
if (old == null) {
oldStyle = 0;
} else {
oldStyle = old.getStyle();
}
int fake = oldStyle & ~tf.getStyle();
if ((fake & Typeface.BOLD) != 0) {
paint.setFakeBoldText(true);
}
if ((fake & Typeface.ITALIC) != 0) {
paint.setTextSkewX(-0.25f);
}
paint.setTypeface(tf);
}
}
I apply the span as follows:
Spannable spannable = new SpannableString(dispStatsPart1()+"\n"+dispStatswords()+"Months");
spannable.setSpan( new CustomTypefaceSpan("sans-serif",Helv_cond_bold), 0, dispStatsPart1().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan( new CustomTypefaceSpan("sans-serif",helv_light), dispStatsPart1().length(), dispStatsPart1().length() +(dispStatswords()+"Months").length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.numberText.setText(spannable);
I want a different font size for the first line and a different font size for the second line, How to achieve that?
So far I have tried modifying my code to:
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
int oldStyle;
Typeface old = paint.getTypeface();
if (old == null) {
oldStyle = 0;
} else {
oldStyle = old.getStyle();
}
int fake = oldStyle & ~tf.getStyle();
if ((fake & Typeface.BOLD) != 0) {
paint.setFakeBoldText(true);
}
if ((fake & Typeface.ITALIC) != 0) {
paint.setTextSkewX(-0.25f);
}
if(flag == 0){
paint.setTextSize(50);
}else{
paint.setTextSize(50);
}
paint.setTypeface(tf);
}
I pass the flags to the constructor:
public CustomTypefaceSpan(String family, Typeface type, int flg) {
super(family);
newType = type;
flag = flg;
}
But the above does not seem to work, the font size is increased or decreased but it happens for both strings.