Created
August 29, 2014 19:25
-
-
Save benvium/4230535b250b4bd75ebe to your computer and use it in GitHub Desktop.
Programatically create a drawable with rounded corners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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