Q:

draw background (checkerboard) java android

I am fairly new to java and android, but am looking for a good tutorial that will get on the right track.   I want to write a function that draws/redraws  a black on white checkerboard pattern to the background of my app's current view.   I don't want to use an actual image, as i want to be able to redraw the background on resize events, ect.  and i want to dynamically change the size of the squares..
Thanks for any help

A:

The most efficient way to do it is to have a Bitmap containing a checkerboard pattern (for instance 2x2 squares) and use a BitmapShader with the REPEAT tile mode:
BitmapShader shader = new BitmapShader(bitmapTemplate, Shader. TileMode. REPEAT, Shader. TileMode. REPEAT);
Paint paint = new Paint();
paint.setShader(shader);

// in your draw method

canvas.drawRect(x, y, width, height, paint);

A:

I required this and needed it to be a little bit more flexible than supplying my own bitmap resources.  So here is a on-the-fly option. 
Call this method in your onCreate() or constructor methods and save the paint.  Then simply use the paint during fill operations in your onDraw(). 
private Paint createCheckerBoard(int pixelSize)
{
    Bitmap bitmap = Bitmap.createBitmap(pixelSize * 2, pixelSize * 2, Bitmap. Config. ARGB_8888);

    Paint fill = new Paint(Paint. ANTI_ALIAS_FLAG);
    fill.setStyle(Paint. Style. FILL);
    fill.setColor(0x22000000);

    Canvas canvas = new Canvas(bitmap);
    Rect rect = new Rect(0, 0, pixelSize, pixelSize);
    canvas.drawRect(rect, fill);
    rect.offset(pixelSize, pixelSize);
    canvas.drawRect(rect, fill);

    Paint paint = new Paint(Paint. ANTI_ALIAS_FLAG);
    paint.setShader(new BitmapShader(bitmap, BitmapShader. TileMode. REPEAT, BitmapShader. TileMode. REPEAT));
    return paint;
}

A:

I've made a custom Drawable which can draw the background checkerboard, see this github repo - CheckerboardDrawable. 
You can use it like this:
yourView.setBackgroundDrawable(CheckerboardDrawable.create());

and it's customizable:
CheckerboardDrawable drawable = new CheckerboardDrawable. Builder()
        .colorOdd(Color. LTGRAY)
        .colorEven(Color. DKGRAY)
        .size(20)
        .build();
yourView.setBackgroundDrawable(drawable);

the output will be:

Hope it can help.