title: How to add round corner to canvas drawrect in Android?
body: <p>I am creating a rectangle in <code>@Override</code> method of <code>ReplacementSpan</code>. How to add <code>RoundCorner</code> and <code>padding</code> to it?</p>
  
  <p>Code:</p>
  
  <pre><code>@Override
  public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
      RectF rect = new RectF(x, top, x + measureText(paint, text, start, end), bottom);
      paint.setColor(mBackgroundColor);
      canvas.drawRect(rect, paint);
      paint.setColor(mForegroundColor);
      canvas.drawText(text, start, end, x, y, paint);
  }
  </code></pre>
  
  <h1>Edit-1</h1>
  
  <p>I am using MeasureText:</p>
  
  <p><code>private float measureText(Paint paint, CharSequence text, int start, int end) {
          return paint.measureText(text, start, end);
      }</code></p>
  
  <h1>Edit-2</h1>
  
  <p>After some suggestions I made these changes and I can see  <code>Rounded</code> corner on <code>Rectangle</code></p>
  
  <pre><code>@Override
  public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
      RectF rect = new RectF(x, top, x + measureText(paint, text, start, end), bottom);
      paint.setColor(mBackgroundColor);
      canvas.drawRoundRect(rect, 15,15,paint);
      paint.setColor(mForegroundColor);
      canvas.drawText(text, start, end, x, y, paint);
  
  }
  </code></pre>
  
  <p>and here is the screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/eLNv6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/eLNv6.png" alt="enter image description here"></a></p>
  
  <p>I am calling <code>draw</code> method from following code:</p>
  
  <pre><code>int currentIndex = 0;
  for (int i = 0; i &lt; words.length - 1; i++) {
              s.setSpan(new CustomDrawble(Color.GRAY, Color.WHITE), currentIndex, currentIndex + words[i].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
              currentIndex += words[i].length() + 1;
          }
  </code></pre>