I want to display text as below in my app. I am using Paint
class with style FILL_AND_STROKE
to achieve this. But only one method setColor()
is available to set the color.
How do I set different stroke and fill colors?
Inside custom TextView (does not work in EditText):
@Override public void onDraw(Canvas canvas) { final ColorStateList textColor = getTextColors(); TextPaint paint = this.getPaint(); paint.setStyle(Style.STROKE); paint.setStrokeJoin(Join.ROUND); paint.setStrokeMiter(10); this.setTextColor(strokeColor); paint.setStrokeWidth(strokeWidth); super.onDraw(canvas); paint.setStyle(Style.FILL); setTextColor(textColor); super.onDraw(canvas); }
Don't use FILL_AND_STROKE. Draw once with FILL and then change the color and draw with STROKE.
(That works for rectangles. I'm not sure STROKE works at all for text. You'll have to try it and find out.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With