/**
* 设置圆角矩形背景,以下四个参数的单位为dp
*
* @param leftup
* @param rightup
* @param leftdown
* @param rightdown
* @param color
* @return
*/
public static Drawable getShapeDrawble(Context context, int leftup, int rightup, int leftdown, int rightdown,
int color) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
float density = displayMetrics.density;
float leftUPRadius = leftup * density;
float rightUpRadius = rightup * density;
float leftDownRadius = leftdown * density;
float rightDownRadius = rightdown * density;
// 左上角,顺时针
float[] outerRadii = { leftUPRadius, leftUPRadius, rightUpRadius, rightUpRadius, leftDownRadius,
leftDownRadius, rightDownRadius, rightDownRadius };
ShapeDrawable shapeDrawable = new ShapeDrawable(new RoundRectShape(outerRadii, null, null));
shapeDrawable.getPaint().setColor(color);
return shapeDrawable;
}