Code example for TextPaint

Methods: getFontMetrics, measureText, setColor, setTextSize

0
		// Update TextPaint and text measurements from attributes 
		invalidateTextPaintAndMeasurements(); 
	} 
 
	private void invalidateTextPaintAndMeasurements() { 
		mTextPaint.setTextSize(mExampleDimension);
		mTextPaint.setColor(mExampleColor);
		mTextWidth = mTextPaint.measureText(mExampleString);
 
		Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
		// mTextHeight = fontMetrics.bottom; 
		mTextHeight = Math.abs(fontMetrics.ascent);
		// mTextHeight = mTextPaint.getFontSpacing(); 
	} 
 
	@Override 
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
 
		if (isInEditMode()) {
			canvas.drawColor(Color.YELLOW);