Android examples for Graphics:Drawable Operation
Create a rectangle shape drawable
//package com.java2s; import android.graphics.drawable.GradientDrawable; public class Main { /**//from w ww .j a va 2 s . c o m * Create a rectangel shape drawable * @param argb color in argb * @param radius corner radius * @return a rectangel shape */ public static GradientDrawable createRectangleShape(int argb, float radius) { GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setCornerRadius(radius); drawable.setColor(argb); return drawable; } /** * Create a rectangel shape drawable * @param argb color in argb * @param radiuses 4 corner radius, left-top, right-top, right-bottom, left-top * @return a rectangel shape */ public static GradientDrawable createRectangleShape(int argb, float[] radiuses) { GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setColor(argb); drawable.setCornerRadii(radiuses); return drawable; } }