代碼給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
相關文章
相關標籤/搜索