Code example for TextPaint

Methods: getTypeface, setFakeBoldText, setTextSkewX, setTypeface

0
	 *  
	 * @attr ref android.R.styleable#TextView_typeface 
	 * @attr ref android.R.styleable#TextView_textStyle 
	 */ 
	public void setSwitchTypeface(final Typeface tf) {
		if (mTextPaint.getTypeface() != tf) {
			mTextPaint.setTypeface(tf);
 
			requestLayout();
			invalidate();
		} 
	} 
 
	/** 
	 * 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, final 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 
			final int typefaceStyle = tf != null ? tf.getStyle() : 0;
			final 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);
		} 
	} 
 
	/**