由网友(变了.散了.算了.)分享简介:我想有我的TextView类的背景,但我不知道怎么办。我尝试使用的OnDraw方法的类,但它不能正常工作。I want to have a background of my TextView class, but I don't know how. I try to use the onDraw method on...
我想有我的TextView类的背景,但我不知道怎么办。我尝试使用的OnDraw方法的类,但它不能正常工作。
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.
下面是我的code为我定制的TextView类。
Here is my code for my custom TextView class.
public class Balls extends TextView{
public Balls(Context context) {
super(context);
// TODO Auto-generated constructor stub
this.setText("ball");
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawCircle(50, 50,30, paint);
}}
任何想法,我怎么能解决这个问题code?谢谢你。
Any idea how can I fix this code? Thanks.
推荐答案
您可以按以下方式设置背景,
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);
}
}
我用
this.setBackgroundColor(R.drawable.imageName);
在构造函数来设置背景Image.Also您可以在同样的方法设置背景色。
in constructor to set Background Image.Also you can set background color in same way.
相关推荐
最新文章