Q:

Changing the stroke width of ShapeDrawable programmatically

I have a ShapeDrawable defined in XML with a given stroke width and corner radius.
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <stroke
        android:width="5dp"
        android:color="@color/focus_highlight" /> <!-- Color is YELLOW -->
    <corners android:radius="5dp" />
</shape>

I wanted to change the stroke width and the color of the drawable programmatically. I am able to change the color of the Drawable, however, I am not able to do the same for the Stroke width and corner radius. Can someone tell how to do this? Here's my code snippet - 
public class MainActivity extends Activity {
    .......
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ......
        RelativeLayout relLayout = (RelativeLayout) findViewById(R.id.relLayout);
        drawView = new DrawView(this);
        relLayout.addView(drawView);        
        .....
    }

    class DrawView extends View {
        .....
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            TypedValue value = new TypedValue();
            final boolean resolved = mContext.getTheme().resolveAttribute(
                    R.attr.acc, value, true);
            if (resolved) {
                drawable.setBounds(100, 300, 300, 500);
                drawable.setColorFilter(Color.RED, Mode.XOR); // Changed color to RED
                drawable.draw(canvas);
            }
        }
    }
}

A:

You can use GradientDrawable to set Stroke For Your View...
GradientDrawable gd = new GradientDrawable(Orientation.BOTTOM_TOP, new int[]{Color.BLUE, Color.GREEN});
gd.setStroke(5, Color.RED);

