View 背景颜色渐变

int colors[] = {0xff9CECFB, 0xff65C7F7, 0xff1296db};

GradientDrawable.Orientation.LEFT_RIGHT 设置渐变的方向 从左到右

GradientDrawable bg =new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colors);

int sdk = android.os.Build.VERSION.SDK_INT;

if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {

activity.findViewById(R.id.head_back).setBackgroundDrawable(bg);

}else {

activity.findViewById(R.id.head_back).setBackground(bg);

}.

你可能感兴趣的:(View 背景颜色渐变)