Android如何以编程方式绘制圆角矩形

时间:2015-01-23 10:20:53

标签: java android android-layout user-interface

我有TextView并且我想以编程方式绘制圆角矩形,我想将该形状设置为TextView的背景?我想动态地改变它的颜色,我已经张贴了这张照片?

enter image description here

1 个答案:

答案 0 :(得分:4)

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);
}

此处查看v =您的textview或按钮或任何内容。