draw Button Text on Canvas - Android Graphics

Android examples for Graphics:Canvas

Description

draw Button Text on Canvas

Demo Code


//package com.java2s;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

public class Main {
    public static void drawButtonText(Canvas canvas, Paint paint,
            Rect btnRect, String text) {
        int nLen = text.length();
        canvas.drawText(text,//  w  ww .j  a  va2 s  .  co  m
                btnRect.left + btnRect.width() / 2 - 4 * nLen, btnRect.top
                        + btnRect.height() / 2 + nLen, paint);
    }
}

Related Tutorials