How can i draw dash line on a canvas. I already tried this:
Paint dashPaint = new Paint();
dashPaint.setARGB(255, 0, 0, 0);
dashPaint.setStyle(Paint.Style.STROKE);
dashPaint.setPathEffect(new DashPathEffect(new float[]{5, 10, 15, 20}, 0));
canvas.drawLine(0, canvas.getHeight() / 2, canvas.getWidth(), canvas.getHeight() / 2, dashPaint);
And it gave me not dash line but a simple one.
You are drawing a line, as per documentation, drawLine function will:
To draw a dashed line, a suggestion is to use the Path primitive
In onDraw()
Snap shot
I have background and dashed line drew over it.
Example
Modify the above according to your needs.