我的类定义如下:
public class Island extends View {
private ShapeDrawable mDrawable;
public Island(Context context) {
super(context);
int width = 50;
int height = 50;
mDrawable = new ShapeDrawable(new OvalShape());
mDrawable.getPaint().setColor(0xff74AC23);
mDrawable.setBounds(0, 0, width, height);
}
public void change() {
mDrawable.getPaint().setColor(Color.BLACK);
}
protected void onDraw(Canvas canvas) {
mDrawable.draw(canvas);
}
为什么当我在对象上调用 change() 时形状不会改变颜色?谢谢。
最佳答案
您需要调用 invalidate 以便 View 知道它需要重绘
关于android - 如何在运行时更改自定义 View 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26766328/