How to set gradient style to paint object? How to set gradient style to paint object? android android

How to set gradient style to paint object?


use the code below..

paint.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));    canvas.drawPath(arrowPath, paint);


If you want more than one color:

// Gradient Shade colors distribution setting uniform for nowprivate val positions = null //floatArrayOf(0f, 0.3f, 0.6f)// Gradient Shade colorsprivate val colors = intArrayOf(        ContextCompat.getColor(context,                R.color.divider_gradient_start_color),        ContextCompat.getColor(context,                R.color.divider_gradient_center_color),        ContextCompat.getColor(context,                R.color.divider_gradient_end_color))

in OnDraw()

// Add ShadergradientPaint.shader = LinearGradient(0f, 0f, measuredWidth.toFloat(),0f,                 colors,                 positions,                Shader.TileMode.CLAMP)canvas.drawPath(path, gradientPaint)