title: Change color at Paint and Canvas on Android
body: <p>Sorry if the question is silly, but I'm new to Android. I read a lot on developer.android.сom, but solutions to my problem is not found, unfortunately.
  Most of the code I found on staсkoverflow, finished the part itself.
  This View inserted in the Activity in FrameLayout, over the text, and allows you to leave notes in the e-book.</p>
  
  <pre><code>import java.util.ArrayList;
  
  import android.content.Context;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.graphics.Path;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.View.OnTouchListener;
  
  public class PaintSurface extends View implements OnTouchListener {
  
      private Canvas canvas;
      private Path path;
      private Paint paint;
      private ArrayList&lt;Path&gt; paths = new ArrayList&lt;Path&gt;();
  
      public PaintSurface(Context context) {
          super(context);
          setFocusable(true);
          setFocusableInTouchMode(true);
  
          this.setOnTouchListener(this);
  
          paint = new Paint();
          paint.setAntiAlias(true);
          paint.setDither(true);
          paint.setStyle(Paint.Style.STROKE);
          paint.setStrokeJoin(Paint.Join.MITER);
          paint.setStrokeCap(Paint.Cap.SQUARE);
          paint.setColor(Color.RED);
          paint.setStrokeWidth(16);
          paint.setAlpha(100);
          canvas = new Canvas();
          path = new Path();
          paths.add(path);
  
      }
  
      @Override
      protected void onSizeChanged(int w, int h, int oldw, int oldh) {
          super.onSizeChanged(w, h, oldw, oldh);
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
  
          for (Path p : paths) {
              canvas.drawPath(p, paint);
          }
  
      }
  
      private float mX, mY;
      private static final float TOUCH_TOLERANCE = 4;
  
      private void touch_start(float x, float y) {
          path.reset();
          path.moveTo(x, y);
          mX = x;
          mY = y;
      }
  
      private void touch_move(float x, float y) {
          float dx = Math.abs(x - mX);
          float dy = Math.abs(y - mY);
          if (dx &gt;= TOUCH_TOLERANCE || dy &gt;= TOUCH_TOLERANCE) {
              path.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
              mX = x;
              mY = y;
          }
  
      }
  
      private void touch_up() {
          path.lineTo(mX, mY);
          canvas.drawPath(path, paint);
  
          path = new Path();
          paths.add(path);
  
      }
  
      @Override
      public boolean onTouch(View arg0, MotionEvent event) {
          float x = event.getX();
          float y = event.getY();
  
          switch (event.getAction()) {
          case MotionEvent.ACTION_DOWN:
              touch_start(x, y);
              invalidate();
              break;
          case MotionEvent.ACTION_MOVE:
              touch_move(x, y);
              invalidate();
              break;
          case MotionEvent.ACTION_UP:
              touch_up();
              invalidate();
              break;
          }
          return true;
  
      }
  
      public void setColor(int color) {
          paint.setColor(color);
  
      }
  }
  </code></pre>
  
  <p>Describe the problem.
  I draw the line of the default color, red. Then, use the setColor() changes to green to draw a green line next to the red line. But the first red line also turns green. Such changes occur if you change the style or the stroke width.
  How is it possible to paint a different color?</p>
  
  <p>A feeling that in a few months this problem would seem to me ridiculous and stupid, and I myself will feel myself silly and I would be ashamed, but now I do not know how to solve this problem...</p>