/StrokeOutlineSpan.java Secret
Created
August 3, 2016 10:05
Star
You must be signed in to star a gist
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
import android.graphics.Canvas; | |
import android.graphics.Color; | |
import android.graphics.Paint; | |
import android.text.style.ReplacementSpan; | |
public class StrokeOutlineSpan extends ReplacementSpan { | |
private int fillColor = Color.WHITE; | |
private int strokeOutlineColor = Color.BLACK; | |
private float strokeWidth = 0; | |
public void setFillColor(int fillColor) { | |
this.fillColor = fillColor; | |
} | |
public void setStrokeOutlineColor(int strokeOutlineColor) { | |
this.strokeOutlineColor = strokeOutlineColor; | |
} | |
public void setStrokeWidth(float strokeWidth) { | |
this.strokeWidth = strokeWidth; | |
} | |
@Override | |
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { | |
return (int) paint.measureText(text, start, end); | |
} | |
@Override | |
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { | |
paint.setStyle(Paint.Style.FILL); | |
paint.setColor(fillColor); | |
canvas.drawText(text, start, end, x, y, paint); | |
if (strokeWidth <= 0) return; | |
paint.setStyle(Paint.Style.STROKE); | |
paint.setColor(strokeOutlineColor); | |
paint.setStrokeWidth(strokeWidth); | |
canvas.drawText(text, start, end, x, y, paint); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment