-1
我有一個「MainActivity.java」類,並且延伸SurfaceView
並實現Runnable
一個內部類「SquashCourtView」。
我想改變背景顏色,但沒有succsess。任何幫助?背景顏色不改變
// all required things are imported
public class MainActivity extends AppCompatActivity {
Canvas canvas;
SquashCourtView squashCourtView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
squashCourtView = new SquashCourtView(this);
setContentView(squashCourtView);
}
class SquashCourtView extends SurfaceView implements Runnable {
Thread ourThread = null;
SurfaceHolder ourHolder;
Paint paint;
public SquashCourtView(Context context) {
super(context);
ourHolder = getHolder();
paint = new Paint();
}
@Override
public void run() {
drawCourt();
}
public void drawCourt() {
if (ourHolder.getSurface().isValid()) {
canvas = ourHolder.lockCanvas();
canvas.drawColor(Color.BLACK);//the background
ourHolder.unlockCanvasAndPost(canvas);
}
}
}