Skip to content

Instantly share code, notes, and snippets.

@benvium
Created August 29, 2014 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benvium/4230535b250b4bd75ebe to your computer and use it in GitHub Desktop.
Save benvium/4230535b250b4bd75ebe to your computer and use it in GitHub Desktop.
Programatically create a drawable with rounded corners
public class RRDrawable extends Drawable {
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
public RRDrawable(int color) {
paint.setColor(color);
paint.setStyle(Paint.Style.FILL);
}
@Override
public void draw(Canvas canvas) {
int radius = PixelUtils.dpToPixels(ctx, 5);
canvas.drawRoundRect(new RectF(0,0,canvas.getWidth(), canvas.getHeight()), radius, radius, paint);
}
@Override
public void setAlpha(int i) {
//.. not supported
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
//.. not supported
}
@Override
public int getOpacity() {
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment