The code for drawing an arrow with Style: Fill is given below:
paint.setColor(Color.parseColor("#bdc0dc"));
paint.setStyle(Style.FILL);
canvas.drawPath(arrowPath, paint);
paint.setColor(Color.BLACK);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(2);
canvas.drawPath(arrowPath, paint);
And the output I obtain is this :
Now what I want do is set style to Gradient(Style.gradient not present in android...) to obtain the arrow similar to the image given below :
How do i do it ? I tried adding style in style.xml but was unable to add gradient there as it accepts item as parameter..
To draw a gradient, select the Gradient tool and click and drag on the canvas. The gradient will be drawn as a transition between the Primary and Secondary colors ( Color Mode) as the mouse moves. After the mouse button is released, the gradient can be adjusted by dragging the Control Nubs .
Flutter painting gradient dart'; // In your paint method final paint = Paint() .. shader = RadialGradient( colors: [ color1, color2, ], ). createShader(Rect. fromCircle( center: offset, radius: radius, ));
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 now
private val positions = null //floatArrayOf(0f, 0.3f, 0.6f)
// Gradient Shade colors
private 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 Shader
gradientPaint.shader = LinearGradient(0f, 0f, measuredWidth.toFloat(),0f,
colors,
positions,
Shader.TileMode.CLAMP)
canvas.drawPath(path, gradientPaint)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With