title: Android Canvas: Create RoundRectShape Object
body: <p>I have created a class for a rectangle shape as it is an object in my application. However now I would like the corners to be rounded. Below you can see it's a bare bones class to create as many rectangles I want with the same attributes. </p>
  
  <pre><code>public class customDrawable extends ShapeDrawable {
  
      public void setCustomDrawableAttributes(ShapeDrawable shapeDrawable){
         int x = 0;
         int y = 0;
         int width = 100;
         int height = 100;
         shapeDrawable.setBounds(x, y-height, x + width,y+height );
     }
  
     public ShapeDrawable createShape(){
         return new ShapeDrawable(new RectShape());
     }
  
  }
  </code></pre>
  
  <p>Update: Without this method I have nothing will be drawn as there is no size. With it it only draws the usual rectangle. (Integer values where changed to not show app specific methods)</p>
  
  <pre><code>public void setDrawableAttributes(ShapeDrawable shapeDrawable){
     int x = 0;
     int y = 500
     int width = 200
     int height = 300
     shapeDrawable.setBounds(x, y-height, x + width,y+height );
  </code></pre>
  
  <p>}</p>
  
  <p>From my research I found that I cannot simply add rounded corners but instead have to create a <code>RoundRectShape shapeDrawable</code>. Every attempt I have made to create a rectangle with rounded corners using this <code>RoundRectShape</code> has failed. Somehow the shape always ends up being a regular rectangle with no rounded corners.</p>
  
  <p>I am looking for a just bare bones class (like the one provided) that creates a roundRectShape drawable. Height and width does not matter as long as it has rounded corners. Must be in Java and not XML. </p>
  
  <p>Links I have tried for creating round rectangles:</p>
  
  <p>1.<a href="https://developer.android.com/reference/android/graphics/drawable/shapes/RoundRectShape.html" rel="nofollow noreferrer">https://developer.android.com/reference/android/graphics/drawable/shapes/RoundRectShape.html</a></p>
  
  <p>2.<a href="http://alvinalexander.com/java/jwarehouse/android/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java.shtml" rel="nofollow noreferrer">http://alvinalexander.com/java/jwarehouse/android/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java.shtml</a></p>
  
  <p>3.<a href="https://www.codota.com/android/scenarios/52c5d269da0a37e1836d6e75/android.graphics.drawable.shapes.RoundRectShape?tag=coyote" rel="nofollow noreferrer">https://www.codota.com/android/scenarios/52c5d269da0a37e1836d6e75/android.graphics.drawable.shapes.RoundRectShape?tag=coyote</a></p>
  
  <p>4.<a href="http://developer.oesf.biz/em/developer/reference/durian/android/graphics/drawable/shapes/RoundRectShape.html" rel="nofollow noreferrer">http://developer.oesf.biz/em/developer/reference/durian/android/graphics/drawable/shapes/RoundRectShape.html</a></p>
  
  <p>5.<a href="https://android.googlesource.com/platform/frameworks/base/+/donut-release/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java" rel="nofollow noreferrer">https://android.googlesource.com/platform/frameworks/base/+/donut-release/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java</a></p>
  
  <p>6.<a href="https://stackoverflow.com/questions/11490611/android-roundrectshape-modify-corner-radii">Android: RoundRectShape: Modify corner radii</a></p>
  
  <p>7.<a href="http://www.programcreek.com/java-api-examples/index.php?api=android.graphics.drawable.shapes.RoundRectShape" rel="nofollow noreferrer">http://www.programcreek.com/java-api-examples/index.php?api=android.graphics.drawable.shapes.RoundRectShape</a></p>
  
  <p>8.<a href="http://www.edumobile.org/android/shape-drawing-example-in-android/" rel="nofollow noreferrer">http://www.edumobile.org/android/shape-drawing-example-in-android/</a>
  9.<a href="http://programtalk.com/java-api-usage-examples/android.graphics.drawable.shapes.RoundRectShape/" rel="nofollow noreferrer">http://programtalk.com/java-api-usage-examples/android.graphics.drawable.shapes.RoundRectShape/</a></p>