美文网首页Android
Android代码控件圆角

Android代码控件圆角

作者: 明日未期 | 来源:发表于2019-11-23 20:47 被阅读0次

    方法

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

    相关文章

      网友评论

        本文标题:Android代码控件圆角

        本文链接:https://www.haomeiwen.com/subject/kvqkwctx.html