代碼設置TextView、Button等控件圓角邊框背景顏色

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章