Android: Adding Background on a Custom TextView class

喜你入骨 提交于 2019-11-29 12:02:28
Anil Jadhav

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!