Android Using Paint to draw dashed line with two different colors

android, graphics, paint

Solution

Try creating two paints with two colours and draw your line two times with different paints where the first one is not dashed while the second one on top is.

If you want transparent spaces inbetween dashes then adjust dashed effect and try changing offset like:

paint.setPathEffect(new DashPathEffect(new float[] {10,10}, 0)); 
paint2.setPathEffect(new DashPathEffect(new float[] {5,15}, 15)); 

Problem

I want to draw a dashed line with two colors. I would like the line to alternate between red and white on even intervals. What I have so far works pretty well, but the space between the dashes it transparent. That is what I am trying to change. My work so far: ``` Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.parseColor("#ED1C24")); paint.setStyle(Paint.Style.STROKE); paint.setPathEffect(new DashPathEffect(new float[] {10,10}, 0)); ``` Thanks all!!

Original source