Paint paint = new Paint(); paint.setColor(Color.BLACK); // 设置画笔透明度以及RGB属性1、a(透明度)1~255越小越透明 。2、R(红色)0~255越小越淡。3、G(绿色) // 0~255。4、B(蓝色)0~255。 paint.setARGB(200, 5, 100, 230); // 设置抗锯齿 注:设置这个属性后会消耗大量资源,绘制图形时会变慢。 paint.setAntiAlias(true); // 设置画笔的大小,也就是粗细。 paint.setStrokeWidth(1); // 设置画笔的样式。1、STROKE:空心图不填充颜色, paint.setStyle(Style.STROKE); // 绘制矩形,1、左边界的位置,2、上边界的位置,3、有边界的位置,4、下边界的位置。 paint.setTextSize(100); canvas.drawRect(200, 100, 300, 400, paint); // 绘制一条线,前俩个参数是x,y的起始位置的坐标,后俩个是x,y的终止位置的坐标。 canvas.drawLine(100, 100, 400, 400, paint); // 绘制圆形,前两个是圆心 x,y坐标,radius:是圆的半径。 canvas.drawCircle(200, 200, 50, paint); canvas.drawText("appde", 150, 300, paint); canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),300,100,paint); Paint backgroundpaint = new Paint(); backgroundpaint.setColor(getResources().getColor( R.color.BackgroundColor)); canvas.drawRect(0, 0, getWidth(), getHeight(), backgroundpaint);Paint blackpaint = new Paint(); blackpaint.setColor(getResources().getColor(R.color.black));Paint strikingpaint = new Paint(); strikingpaint.setColor(getResources().getColor(R.color.Striking));Paint brightpaint = new Paint(); brightpaint.setColor(getResources().getColor(R.color.Bright));for (int i = 0; i < 9; i++) { canvas.drawLine(0, i * height, getWidth(), i * height, strikingpaint); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, brightpaint); canvas.drawLine(i * width, 0, i * width, getHeight(), strikingpaint); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), brightpaint); } for (int i = 0; i < 9; i++) { if (i % 3 != 0) { continue; } canvas.drawLine(0, i * height, getWidth(), i * height, blackpaint); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, brightpaint); canvas.drawLine(i * width, 0, i * width, getHeight(), blackpaint); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), brightpaint); }Paint textpaint = new Paint(); textpaint.setColor(Color.BLACK); textpaint.setStyle(Paint.Style.STROKE); textpaint.setTextSize(height * 0.75f); textpaint.setTextAlign(Paint.Align.CENTER); float x = width / 2; canvas.drawText("1", 3 * width + x, 61, textpaint);