Skip to content

Instantly share code, notes, and snippets.

@drakeet
Created November 10, 2015 09:32
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 drakeet/53074003f41f4cae9cf0 to your computer and use it in GitHub Desktop.
Save drakeet/53074003f41f4cae9cf0 to your computer and use it in GitHub Desktop.
TextDrawable
public class TextDrawable extends Drawable {
private final String text;
private final Paint paint;
public TextDrawable(String text) {
this.text = text;
this.paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(22f);
paint.setAntiAlias(true);
paint.setFakeBoldText(true);
paint.setShadowLayer(6f, 0, 0, Color.BLACK);
paint.setStyle(Paint.Style.FILL);
paint.setTextAlign(Paint.Align.LEFT);
}
@Override
public void draw(Canvas canvas) {
canvas.drawText(text, 0, 0, paint);
}
@Override
public void setAlpha(int alpha) {
paint.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
paint.setColorFilter(cf);
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
}
@drakeet
Copy link
Author

drakeet commented Nov 10, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment