i was wondering how one can draw on a canvas and use different colors?
I.e. you draw a yellow path and after clickling a button you draw again but with another color.
Currently, after changing the color (by button click) the old path(es) change color, too.
This confuses me because I create a new Paint() object (with a new color) after button click.
Here are the important code snippets:
The paint object
Using java Syntax Highlighting
- public void setMpaint(int color) {
- mPaint = new Paint();
- mPaint.setDither(false);
- mPaint.setColor(color);
- mPaint.setStyle(Paint.Style.STROKE);
- mPaint.setStrokeJoin(Paint.Join.ROUND);
- mPaint.setStrokeCap(Paint.Cap.ROUND);
- mPaint.setStrokeWidth(6);
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
gets called at the beginning of the Activity and everytime the button is clicked.
the onDraw method
Using java Syntax Highlighting
- @Override
- public void onDraw(final Canvas canvas) {
- for (Path path : _graphics) {
- canvas.drawPath(path, mPaint);
- }
- }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
I have a couple of coords and draw a (couple of ...) path.
I thought when creating a new Paint() object (after button click), the old path (which was drawn with the old Paint() object) is not influenced. Am I wrong?
Thank you,
R.


