简体   繁体   English

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

[英]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 ? 我有TextView ,我想以编程方式绘制Rounded Rectangle形状,并将该形状设置为TextView的背景吗? and I want to change it colors dynamically, I have posted the picture ? 我想动态更改它的颜色,我已经贴了图片吗?

在此处输入图片说明

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. 在这里,视图v =您的textview或按钮或其他任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM