Custom Textview With Html Text And Custom Font Whole Android Application
I have created a custom textview to set the custom font and to set the html text for whole application. Because my app has both the functions in many places. In this case, i can ab
Solution 1:
Have you consideret to use SpannbleString? How can I use TypefaceSpan or StyleSpan with a custom Typeface?
Here is different spans that you can apply on SpannableString.
publicvoidsetSpan(){
Spannablespantext=newSpannableString("My application");
spantext.setSpan(newStyleSpan(Typeface.BOLD), 3//Start of span, 6//End of span, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);TypefaceHelveticaNeueBoldItalic= Typeface.createFromAsset(getActivity().getAssets(), "fonts/HelveticaNeueBoldItalic.ttf");
spantext.setSpan(newCustomTypefaceSpan("", HelveticaNeueBoldItalic ), 0, text.lenght(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView text;
text.setText(spantext);
}
publicclassCustomTypefaceSpanextendsTypefaceSpan {
privatefinal Typeface newType;
publicCustomTypefaceSpan(String family, Typeface type) {
super(family);
newType = type;
}
@OverridepublicvoidupdateDrawState(TextPaint ds) {
applyCustomTypeFace(ds, newType);
}
@OverridepublicvoidupdateMeasureState(TextPaint paint) {
applyCustomTypeFace(paint, newType);
}
privatestaticvoidapplyCustomTypeFace(Paint paint, Typeface tf) {
int oldStyle;
Typefaceold= paint.getTypeface();
if (old == null) {
oldStyle = 0;
} else {
oldStyle = old.getStyle();
}
intfake= oldStyle & ~tf.getStyle();
if ((fake & Typeface.BOLD) != 0) {
paint.setFakeBoldText(true);
}
if ((fake & Typeface.ITALIC) != 0) {
paint.setTextSkewX(-0.25f);
}
paint.setTypeface(tf);
}
}
Post a Comment for "Custom Textview With Html Text And Custom Font Whole Android Application"