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); } } }
You’ve got great insights about how to paint and draw, keep up the good work!