To do this, you need to create a new Paint for each drawn object. This is because when you redraw the Canvas it refers to the same Paint object every time, so all paths will use this paint.
First, I would modify your paths array containing both Paint and Path . You can achieve this using the Android Pair type.
ArrayList<Pair<Path, Paint>> paths = new ArrayList<Pair<Path, Paint>>();
You will also have to convert the undonePaths variable this way.
Then in your touch_up() method you need to add this new Paint object.
Paint newPaint = new Paint(mPaint);
Finally, your loop should also be adjusted:
for (Pair<Path, Paint> p : paths) { canvas.drawPath(p.first, p.second); }
This is a fairly intense amount of memory, so you will need to take care to reset these elements when they are no longer in use, but in order to have so many different colors, you must have all these different Paint objects.
source share