If you simply want to draw a rect on a plain-colored background you could try this:
private Paint rectPaint = new Paint();
private Rect rect = new Rect(0, 0, 5, 5);
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.BLUE);
canvas.drawRect(rect, rectPaint);
}
This code does not move your rect yet. You could use the following method to add an offset to the previously defined rect, thus moving it on the canvas.
public void moveRect(int dx,int dy){
rect.offset(dx, dy);
}
Where exactly this should happen depends on the rest of your code. (Maybe each time onDraw() is called?)
If your aim is to draw different bitmaps on a canvas you should try this method
canvas.drawBitmap(bitmap, left, top, paint);
For this you can either load the bitmap from a resource:
Bitmap backgroundBitmap = BitmapFactory.decodeResource(context,
R.drawable.your_background_bitmap);
or initialize an empty Bitmap and draw to this bitmap using a Canvas:
Bitmap backgroundBitmap = Bitmap.createBitmap(getWidth(), getHeight(),
Config.ARGB_8888);
Canvas backgroundCanvas = new Canvas(backgroundBitmap);
backgroundCanvas.drawColor(Color.BLUE);
If you have more information on what your code is about (e.g. a custom View, a game loop) I could help you with more precise answers.