Created
November 10, 2015 09:32
-
-
Save drakeet/53074003f41f4cae9cf0 to your computer and use it in GitHub Desktop.
TextDrawable
This file contains hidden or 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 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got it from here: http://stackoverflow.com/questions/3972445/how-to-put-text-in-a-drawable