title: Android Google Map cleared by PorterDuff.Mode.CLEAR
body: <p>I'm trying to draw a rectangle above the google map to crop a portion of the map. </p>
  
  <p>I placed a googleMap and a custom layout with a canvas like this.</p>
  
  <pre><code>&lt;FrameLayout&gt;
     &lt;FrameLayout/&gt;//conatiner for SupportMapFragment
     &lt;MyCustomLayout/&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>Inside MyCustomLayout, the paints are initiated like this.</p>
  
  <pre><code>        linedPaint.setStyle(Paint.Style.STROKE);
          linedPaint.setStrokeWidth(5f);
          linedPaint.setColor(getResources().getColor(R.color.colorBlack));
          linedPaint.setPathEffect(new DashPathEffect(new float[]{10, 10}, 0));
  
          bgPaint = new Paint();
          bgPaint.setColor(0x70FFFFFF);
  
          transparentPaint = new Paint();
          transparentPaint.setStyle(Paint.Style.FILL);
          transparentPaint.setColor(getResources().getColor(android.R.color.transparent));
          transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
  </code></pre>
  
  <p>onDraw is as below.</p>
  
  <pre><code>@Override
  protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
  
      try {
  
          canvas.drawRect(0, 0, getWidth(), getHeight(), bgPaint);
          canvas.drawRect(mClickStartX, mClickStartY, mClickEndX, mClickEndY, transparentPaint);
          canvas.drawRect(mClickStartX, mClickStartY, mClickEndX, mClickEndY, linedPaint);
  
  
      } catch (Exception e) {
          ErrorController.showError(e);
      }
  }
  </code></pre>
  
  <p>This will draw a dim white background above the map, and when the user clicks and drags on it, it will draw a transparent rectangle.</p>
  
  <p>But, when the transparentPaint's xfermode is set to <B>PorterDuff.Mode.CLEAR</B>, it clears the map itself, resulting as a <B>black rectangle</B> shown as below.</p>
  
  <p><a href="https://i.stack.imgur.com/fV7mL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fV7mL.png" alt="enter image description here"></a></p>
  
  <p>When changing the xfermode to OVERLAY, it doesn't change the map to black, but the background of the canvas will not be changed as I expect. </p>
  
  <p>When switching to a Naver Map fragment, it works as I expect it to be. What can I try to make this work? Please help!</p>