方式1:硬代码实现
GradientDrawable在Android中便是shape标签的代码实现,利用GradientDrawable也可以创建出各种形状。
GradientDrawable background = new GradientDrawable();
background.setShape(GradientDrawable.RECTANGLE);
//设置背景色
background.setColor(backColor);
//设置边线粗细,颜色
background.setStroke(2,strokeColor);
//设置圆角弧度
background.setCornerRadius(18f);
方式2:xml文件