Return to Snippet

Revision: 45713
at May 5, 2011 20:25 by Znupi


Initial Code
public static ShapeDrawable createUserDrawable(String color) {
    ShapeDrawable drawable = new ShapeDrawable();
    drawable.setBounds(0, 0, 10, 20);
    float radius = 4;
    float[] radii = new float[] {radius, radius, radius, radius, radius, radius, radius, radius};
    Shape shape = new RoundRectShape(radii, new RectF(), radii);
    drawable.setShape(shape);
    Paint paint = drawable.getPaint();
    paint.setColor(Color.parseColor(color));
    return drawable;
}

Initial URL

                                

Initial Description
This creates a rounded rectangle (10x20) with a given color (such as #AABBCC) as a drawable, which you can later use anywhere (I use it in TextView.setCompoundDrawables).

Initial Title
Dynamic rounded rectangle [android]

Initial Tags
android

Initial Language
Java