Saturday, September 8, 2012

Draw text with shadow on canvas

More examples of drawing on canvas of custom View listed HERE.

To draw text with shadow on canvas, Modify onDraw(Canvas canvas) method of MyView.java in the exercise.

 @Override
 protected void onDraw(Canvas canvas) {

  canvas.drawColor(Color.GRAY);

        Paint shadowPaint = new Paint();
        shadowPaint.setAntiAlias(true);
        shadowPaint.setColor(Color.WHITE);
        shadowPaint.setTextSize(45.0f);
        shadowPaint.setStrokeWidth(2.0f);
        shadowPaint.setStyle(Paint.Style.STROKE);
        shadowPaint.setShadowLayer(5.0f, 10.0f, 10.0f, Color.BLACK);
        
        canvas.drawText("http://android-er.blogspot.com/", 50, 200, shadowPaint);
  
 };


Draw text with shadow on canvas


download filesDownload the files.


4 comments:

  1. Nice one. Thanks for the posting.

    ReplyDelete
  2. Thanks, made a handy reference, not to mention the top google result for "android drawtext with drop shadow"!

    ReplyDelete