Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Paint; import android.graphics.Rect; import android.widget.Button; public class Main { public static int getButtonTextWidth(Button button, String text) { Rect bounds = new Rect(); Paint buttonPaint = button.getPaint(); buttonPaint.getTextBounds(text, 0, text.length(), bounds); return bounds.width(); } }