方法
setCorner(view, c1, c2, c3, c4, color)
setCorner(view, c1, c2, c3, c4, color, stroke, strokeColor)
参数
名称 | 注释 | 名称 | 注释 | |
---|---|---|---|---|
view | 视图 | color | 背景颜色String
|
|
c1 | 左上int
|
stroke | 边框厚度int
|
|
c2 | 右上int
|
strokeColor | 边框颜色String
|
|
c3 | 右下int
|
|||
c4 | 左下int
|
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
public class ViewUtil {
public static void setCorner(View view, int c1, int c2, int c3, int c4, String color) {
setCorner(view, c1, c2, c3, c4, color, 0, "#ffffff");
}
public static void setCorner(View view, int c1, int c2, int c3, int c4, String color, int stroke, String strokeColor) {
try {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadii(new float[]{c1, c1, c2, c2, c3, c3, c4, c4});
shape.setColor(Color.parseColor(color));
shape.setStroke(stroke, Color.parseColor(strokeColor));
view.setBackgroundDrawable(shape);
} catch (Exception e) {
}
}
}
网友评论