2016-08-28 16 views

答えて

0

Check this link it is the best way as my point of view

くださいTextProgressBar

public class TextProgressBar extends ProgressBar { 
private String text; 
private Paint textPaint; 

public TextProgressBar(Context context) { 
    super(context); 
    text = "HP"; 
    textPaint = new Paint(); 
    textPaint.setColor(Color.BLACK); 
} 

public TextProgressBar(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    text = "HP"; 
    textPaint = new Paint(); 
    textPaint.setColor(Color.BLACK); 
} 

public TextProgressBar(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    text = "HP"; 
    textPaint = new Paint(); 
    textPaint.setColor(Color.BLACK); 
} 

@Override 
protected synchronized void onDraw(Canvas canvas) { 
    // First draw the regular progress bar, then custom draw our text 
    super.onDraw(canvas); 
    Rect bounds = new Rect(); 
    textPaint.getTextBounds(text, 0, text.length(), bounds); 
    int x = getWidth()/2 - bounds.centerX(); 
    int y = getHeight()/2 - bounds.centerY(); 
    canvas.drawText(text, x, y, textPaint); 
} 

public synchronized void setText(String text) { 
    this.text = text; 
    drawableStateChanged(); 
} 

public void setTextColor(int color) { 
    textPaint.setColor(color); 
    drawableStateChanged(); 
} 

}私はすでにこのリンクで答えを与え

Progressbar android with text inside

関連する問題