![](https://cos-cdn.shuashuati.com/pipixue-web/2020-1231-2005-12/ti_inject-812ce.png)
public class MySurfaceView extends SurfaceView implements Callback { // 用于控制 SurfaceView private SurfaceHolder sfh; // 声明一个画笔 private Paint paint; // 文本的坐标 private int textX = 10, textY = 10; private Canvas canvas; public MySurfaceView(Context context) { super(context); sfh = this.getHolder(); paint = new Paint(); paint.setColor(Color.WHITE); // 设置焦点 setFocusable(true); } @Override public void surfaceCreated(SurfaceHolder holder) { myDraw (); } public void myDraw() { try { canvas = sfh.lockCanvas(); if (canvas != null) { canvas.drawRGB(0, 0, 0); canvas.drawText("Game", textX, textY, paint); } } catch (Exception e) { // TODO: handle exception } finally { if (canvas != null) sfh.unlockCanvasAndPost(canvas); } } }