Pages

How to fill a Paint in Android with a linear gradient?


protected void onDraw(Canvas canvas)
{
    super.onDraw(canvas);
    Paint p = new Paint();
    // start at 0,0 and go to 0,max to use a vertical
    // gradient the full height of the screen.
    p.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
    canvas.drawPaint(p);
}

3 comments:

Anonymous said...

Thanks!

Anonymous said...

Thanks it works great!

Mert Gülsoy said...

Thank you. Works very well.