Code example for TextPaint

Methods: getTypeface, setColor, setFakeBoldText, setTextSize, setTextSkewX, setTypeface

0
    @Override 
    public void updateDrawState(TextPaint ds) {
        updateMeasureState(ds);
 
        if (mTextColor != null) {
            ds.setColor(mTextColor.getColorForState(ds.drawableState, 0));
        } 
 
        if (mTextColorLink != null) {
            ds.linkColor = mTextColor.getColorForState(ds.drawableState, 0);
        } 
    } 
 
    @Override 
    public void updateMeasureState(TextPaint ds) {
        if (mTypeface != null || mStyle != 0) {
            Typeface tf = ds.getTypeface();
            int style = 0;
 
            if (tf != null) {
                style = tf.getStyle();
            } 
 
            style |= mStyle;
 
            if (mTypeface != null) {
                tf = Typeface.create(mTypeface, style);
            } else if (tf == null) {
                tf = Typeface.defaultFromStyle(style);
            } else { 
                tf = Typeface.create(tf, style);
            } 
 
            int fake = style & ~tf.getStyle();
 
            if ((fake & Typeface.BOLD) != 0) {
                ds.setFakeBoldText(true);
            } 
 
            if ((fake & Typeface.ITALIC) != 0) {
                ds.setTextSkewX(-0.25f);
            } 
 
            ds.setTypeface(tf);
        } 
 
        if (mTextSize > 0) {
            ds.setTextSize(mTextSize);
        } 
    } 
}