Android 代码设置TextView、Button等控件圆角边框背景颜色

来源:互联网 发布:卖esse爱喜烟的淘宝店 编辑:程序博客网 时间:2024/05/22 03:14

int strokeWidth = 5; // 3dp 边框宽度
    int roundRadius = 15; // 8dp 圆角半径
    int strokeColor = Color.parseColor("#2E3135");//边框颜色
    int fillColor = Color.parseColor("#DFDFE0");//内部填充颜色

    GradientDrawable gd = new GradientDrawable();//创建drawable
    gd.setColor(fillColor);
    gd.setCornerRadius(roundRadius);
    gd.setStroke(strokeWidth, strokeColor);
setBackgroundDrawable(gd);但是如果想设置Gradient的渐变色该咋办呢?方法是改变GradientDrawable的创建方法:int

colors[] = { 0xff255779 , 0xff3e7492, 0xffa6c0cd };//分别为开始颜色,中间夜色,结束颜色

GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors);


闲聊群 : 668524118
本群主要用于编程技术 ,及创意作品 ,思维架构的交流 ,欢迎喜欢创新 ,热爱生活的朋友加入 !

阅读全文
0 0
原创粉丝点击