Code example for TextPaint

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

0
     * from the specified TextAppearance resource. 
     */ 
    public void setSwitchTextAppearance(Context context, int resid) {
        mTextColors = getTextColors();
         
        float ts = mTextPaint.getTextSize(); /* TODO */
        if (ts != mTextPaint.getTextSize()) {
            mTextPaint.setTextSize(ts);
            requestLayout();
        } 
 
        setSwitchTypeface(Typeface.DEFAULT, Typeface.NORMAL);
    } 
 
    /** 
     * Sets the typeface and style in which the text should be displayed on the 
     * switch, and turns on the fake bold and italic bits in the Paint if the 
     * Typeface that you provided does not have all the bits in the 
     * style that you specified. 
     */ 
    public void setSwitchTypeface(Typeface tf, int style) {
        if (style > 0) {
            if (tf == null) {
                tf = Typeface.defaultFromStyle(style);
            } else { 
                tf = Typeface.create(tf, style);
            } 
 
            setSwitchTypeface(tf);
            // now compute what (if any) algorithmic styling is needed 
            int typefaceStyle = tf != null ? tf.getStyle() : 0;
            int need = style & ~typefaceStyle;
            mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
            mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
        } else { 
            mTextPaint.setFakeBoldText(false);
            mTextPaint.setTextSkewX(0);
            setSwitchTypeface(tf);
        } 
    } 
 
    /** 
     * Sets the typeface in which the text should be displayed on the switch. 
     * Note that not all Typeface families actually have bold and italic 
     * variants, so you may need to use 
     * {@link #setSwitchTypeface(Typeface, int)} to get the appearance 
     * that you actually want. 
     * 
     * @attr ref android.R.styleable#TextView_typeface 
     * @attr ref android.R.styleable#TextView_textStyle 
     */ 
    public void setSwitchTypeface(Typeface tf) {
        if (mTextPaint.getTypeface() != tf) {
            mTextPaint.setTypeface(tf);
 
            requestLayout();
            invalidate();
        } 
    }