Achin
Achin

Reputation: 1252

Android how to draw Rounded Rectangle shape programmatically

I have TextView and I want to draw Rounded Rectangle shape programmatically and I want to set that shape as a Background of TextView? and I want to change it colors dynamically, I have posted the picture ?

enter image description here

Upvotes: 2

Views: 5598

Answers (1)

Ravi
Ravi

Reputation: 35589

public static void makeRoundCorner(int bgcolor,int radius,View v,int strokeWidth,int strokeColor)
{
    GradientDrawable gdDefault = new GradientDrawable();
    gdDefault.setColor(bgcolor);
    gdDefault.setCornerRadius(radius);
    gdDefault.setStroke(strokeWidth, strokeColor);
    v.setBackgroundDrawable(gdDefault);
}

here View v = your textview or button or anything.

Upvotes: 6

Related Questions