Dynamic rounded rectangle [android]


/ Published in: Java
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. public static ShapeDrawable createUserDrawable(String color) {
  2. ShapeDrawable drawable = new ShapeDrawable();
  3. drawable.setBounds(0, 0, 10, 20);
  4. float radius = 4;
  5. float[] radii = new float[] {radius, radius, radius, radius, radius, radius, radius, radius};
  6. Shape shape = new RoundRectShape(radii, new RectF(), radii);
  7. drawable.setShape(shape);
  8. Paint paint = drawable.getPaint();
  9. paint.setColor(Color.parseColor(color));
  10. return drawable;
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.