title: Android - How to change color in setColor
body: <p>I want to create a drawing app, and it works clearly but it is still far away from my goal.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      DrawingView dv;
      private Paint mPaint;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
  
          dv = new DrawingView(this);
          setContentView(dv);
  
          mPaint = new Paint();
          mPaint.setAntiAlias(true);
          mPaint.setDither(true);
          mPaint.setColor(Color.BLUE);
          mPaint.setStyle(Paint.Style.STROKE);
          mPaint.setStrokeJoin(Paint.Join.ROUND);
          mPaint.setStrokeCap(Paint.Cap.ROUND);
          mPaint.setStrokeWidth(5);
      }
  
      public class DrawingView extends View {
  
          public int width;
          public int height;
          private Bitmap mBitmap;
          private Canvas mCanvas;
          private Path mPath;
          private Paint mBitmapPaint;
          Context context;
          private Paint circlePaint;
          private Path circlePath;
  
          public DrawingView(Context c) {
              super(c);
              context = c;
              mPath = new Path();
              mBitmapPaint = new Paint(Paint.DITHER_FLAG);
              circlePaint = new Paint();
              circlePath = new Path();
              circlePaint.setAntiAlias(true);
              circlePaint.setColor(Color.RED);
              circlePaint.setStyle(Paint.Style.STROKE);
              circlePaint.setStrokeJoin(Paint.Join.MITER);
              circlePaint.setStrokeWidth(4f);
          }
  
          @Override
          protected void onSizeChanged(int w, int h, int oldw, int oldh) {
              super.onSizeChanged(w, h, oldw, oldh);
  
              //mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
              mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.asd) //--&gt;here load your image
                      .copy(Bitmap.Config.ARGB_8888, true);
              mCanvas = new Canvas(mBitmap);
          }
  
          @Override
          protected void onDraw(Canvas canvas) {
              super.onDraw(canvas);
  
              canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
              canvas.drawPath(mPath, mPaint);
              canvas.drawPath(circlePath, circlePaint);
          }
  
          private float mX, mY;
          private static final float TOUCH_TOLERANCE = 4;
  
          private void touch_start(float x, float y) {
              mPath.reset();
              mPath.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) {
                  mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
                  mX = x;
                  mY = y;
  
                  circlePath.reset();
                  circlePath.addCircle(mX, mY, 30, Path.Direction.CW);
              }
          }
  
          private void touch_up() {
              mPath.lineTo(mX, mY);
              circlePath.reset();
              // commit the path to our offscreen
              mCanvas.drawPath(mPath, mPaint);
              // kill this so we don't double draw
              mPath.reset();
          }
  
          @Override
          public boolean onTouchEvent(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 class FingerPaintActivity extends Activity
          implements ColorPickerDialog.OnColorChangedListener{
  
      MyView mv;
      AlertDialog dialog;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          mv= new MyView(this);
          mv.setDrawingCacheEnabled(true);
          mv.setBackgroundResource(R.drawable.afor);//set the back ground if you wish to
          setContentView(mv);
          mPaint = new Paint();
          mPaint.setAntiAlias(true);
          mPaint.setDither(true);
          mPaint.setColor(0xFFFF0000);
          mPaint.setStyle(Paint.Style.STROKE);
          mPaint.setStrokeJoin(Paint.Join.ROUND);
          mPaint.setStrokeCap(Paint.Cap.ROUND);
          mPaint.setStrokeWidth(20);
          mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 },
                  0.4f, 6, 3.5f);
          mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
      }
  
      private Paint       mPaint;
      private MaskFilter mEmboss;
      private MaskFilter  mBlur;
  
      public void colorChanged(int color) {
          mPaint.setColor(color);
      }
  
      public class MyView extends View {
  
          private static final float MINP = 0.25f;
          private static final float MAXP = 0.75f;
          private Bitmap mBitmap;
          private Canvas mCanvas;
          private Path mPath;
          private Paint   mBitmapPaint;
          Context context;
  
          public MyView(Context c) {
              super(c);
              context=c;
              mPath = new Path();
              mBitmapPaint = new Paint(Paint.DITHER_FLAG);
  
          }
  
          @Override
          protected void onSizeChanged(int w, int h, int oldw, int oldh) {
              super.onSizeChanged(w, h, oldw, oldh);
              //mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
              mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.asd) //--&gt;here load your image
                      .copy(Bitmap.Config.ARGB_8888, true);
              mCanvas = new Canvas(mBitmap);
  
          }
  
          @Override
          protected void onDraw(Canvas canvas) {
              super.onDraw(canvas);
  
              canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
              canvas.drawPath(mPath, mPaint);
          }
  
          private float mX, mY;
          private static final float TOUCH_TOLERANCE = 4;
  
          private void touch_start(float x, float y) {
              //showDialog();
              mPath.reset();
              mPath.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) {
                  mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
                  mX = x;
                  mY = y;
              }
          }
  
          private void touch_up() {
              mPath.lineTo(mX, mY);
              // commit the path to our offscreen
              mCanvas.drawPath(mPath, mPaint);
              // kill this so we don't double draw
              mPath.reset();
              mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN));
              //mPaint.setMaskFilter(null);
          }
  
          @Override
          public boolean onTouchEvent(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;
          }
      }
  }
  </code></pre>
  
  <p>This is what my app looks like:</p>
  
  <p><img src="https://i.stack.imgur.com/0ccS2l.png" alt="preview my app, you can check and you will be understand what i mean"></p>
  
  <ol>
  <li><p>I want to change color draw from blue to brown. I changed <code>mPaint.setColor(Color.BROWN);</code> and it failed.</p></li>
  <li><p>If you check my preview app, you'll see that I want to create a business logic where: If user is drawing and it's not completed, the app will show a message like "sorry you have not finished the drawing" and I still look for the way to do it. I don't know if it's possible, is it?</p></li>
  </ol>