代码给textview设置倒圆角,简单暴力

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);

参考:java

http://stackoverflow.com/questions/17667964/how-to-create-shape-with-solid-corner-stroke-in-java-code
http://stackoverflow.com/questions/4177401/gradientdrawable-in-code
http://www.iteye.com/topic/1117635
相关文章
相关标签/搜索