Olá!
Fiz uns botoes personalizados para Android e usei NinePatch, como mostra no site: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
Os botoes estão funcionando muito bem, mas o texto não está aparecendo.
O que eu fiz de errado?
Abaixo segue meu código da minha classe Botao:
[code]public class Botao extends Button {
private boolean isPressed = false;
public Botao(Context context) {
super(context);
setText("teste");
}
@Override
public void onDraw(Canvas canvas) {
Bitmap bitmap;
if (isPressed) {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.botaoselecionado);
} else {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.botaonormal);
}
NinePatchDrawable nine = new NinePatchDrawable(bitmap, bitmap.getNinePatchChunk(), new Rect(0, 0, getWidth(), getHeight()), "botao");
setBackgroundDrawable(nine);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
isPressed = true;
invalidate();
} else if (event.getAction() == MotionEvent.ACTION_UP) {
isPressed = false;
invalidate();
}
return super.onTouchEvent(event);
}
}[/code]