Code example for Paint

Methods: getTextBoundssetAntiAliassetColorsetTextSize

0
	} 
	 
	private void drawBox(Canvas canvas, float point){
		point = -point;
		 
		Paint mPaint = new Paint();
		mPaint.setAntiAlias(true);
		 
		int nBoxWidth = this.getWidth() / 2;
		int nFontSize =  this.getHeight() / 2;
		int nFontTop = this.getHeight() / 2 + this.getHeight() / 5;
		//绘制On 
		mPaint.setColor(Color.rgb(0x33, 0x33, 0xEE));
		canvas.drawRoundRect(new RectF(point, 0, point + nBoxWidth, this.getHeight()), 4.0f, 4.0f, mPaint);
		//绘制Off 
		mPaint.setColor(Color.rgb(0x33, 0x33, 0x33));
		canvas.drawRoundRect(new RectF(point + nBoxWidth * 2, 0, point + nBoxWidth * 3, this.getHeight()), 4.0f, 4.0f, mPaint);
		//绘制中控按钮 
		mPaint.setColor(Color.rgb(0x66, 0x66, 0x66));
		canvas.drawRoundRect(new RectF(point + nBoxWidth - 4, 0, point + nBoxWidth * 2 + 4 , this.getHeight()), 0.0f, 0.0f, mPaint);	
		//绘制文字部分 
		mPaint.setColor(Color.rgb(0xFF, 0xFF, 0xFF));
		mPaint.setTextSize(nFontSize);
		Rect rect = new Rect();
		//获得文字ON的宽度 
		mPaint.getTextBounds(this.strON, 0, this.strON.length(), rect);
		 
		int nFontWidth = rect.width();
		 
		canvas.drawText(this.strON, point + (nBoxWidth - nFontWidth) / 2, nFontTop, mPaint);
		//获得文字OFF的宽度 
		mPaint.getTextBounds(this.strOFF, 0, this.strOFF.length(), rect);
		 
		nFontWidth = rect.width();
		 
		canvas.drawText(this.strOFF, point + nBoxWidth * 2 + (nBoxWidth - nFontWidth) / 2 , nFontTop, mPaint);
	}