The following example shows how to draw a rectangle using the Paint Class in ANDROID. Just copy and paste the following code to your file and you are done.

package Draw2.pack;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

public class Draw2 extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(new myView(this));
  }

  private class myView extends View{

      public myView(Context context) {
          super(context);
      }

      @Override
      protected void onDraw(Canvas canvas) {

          Paint myPaint = new Paint();
          myPaint.setColor(Color.GREEN);
          myPaint.setStyle(Paint.Style.STROKE);
          myPaint.setStrokeWidth(3);
          canvas.drawRect(10, 10, 100, 100, myPaint);
      }
  }
}
 

One Comment

  1. drawing tutorials June 22, 2011 at 8:45 pm

    You’ve got great insights about how to paint and draw, keep up the good work!

     

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.