I want to have a background of my TextView class, but I don\'t know how. I try to use the onDraw method on the class but it is not working.
Here is my code for my cu
Try setBackground or setBackgroundResource
See Scale Drawable and Shape Drawable
You can set Background in following way,
public class Balls extends TextView{
public Balls(Context context) {
super(context);
this.setText("ball");
this.setBackgroundColor(R.drawable.imageName);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawCircle(50, 50,30, paint);
}
}
I used
this.setBackgroundColor(R.drawable.imageName);
in constructor to set Background Image.Also you can set background color in same way.