title: How to programmatically round corners and set random background colors
body: <p>I'd like to round the corners of a view and also change the color of the view based on the contents at runtime.</p>
  
  <pre><code>TextView v = new TextView(context);
  v.setText(tagsList.get(i));
  if(i%2 == 0){
      v.setBackgroundColor(Color.RED);
  }else{
      v.setBackgroundColor(Color.BLUE);
  }
  
  v.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
  v.setPadding(twoDP, twoDP, twoDP, twoDP);               
  v.setBackgroundResource(R.drawable.tags_rounded_corners);
  </code></pre>
  
  <p>I was hoping setting a drawable and color would overlap, but they do not. Whichever one I execute second is the resulting background.</p>
  
  <p>Is there any way to programmatically create this view, keeping in mind that the background color won't be decided until runtime?</p>
  
  <p>edit: I'm only swapping between red and blue now for testing. Later the color will be choosable by the user.</p>
  
  <p>edit:</p>
  
  <p>tags_rounded_corners.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" &gt;
      &lt;corners 
           android:bottomRightRadius="2dp" 
           android:bottomLeftRadius="2dp" 
           android:topLeftRadius="2dp" 
           android:topRightRadius="2dp"/&gt;
  &lt;/shape&gt;
  </code></pre>