How to draw text with different stroke and fill colors?
Inside custom TextView (does not work in EditText):
@Overridepublic 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);}
I used the first solution above to come up with this idea: put down a larger STROKE, text and then overlay it with a smaller FILL_AND_STROKE text:
mScorePaint = new TextPaint();mScorePaint.setTextSize(63);mScorePaint.setStyle(Style.STROKE);mScorePaint.setStrokeJoin(Join.ROUND);mScorePaint.setStrokeMiter(10.0f);mScorePaint.setStrokeWidth(frameWidth/50.0f); // about 12mScorePaint.setColor(0xffff0000); // blackc.drawText(Integer.toString(mScore), x, y, mScorePaint); // red firstmScorePaint.setStrokeWidth(frameWidth/125.0f); // about 5mScorePaint.setColor(0xff000000); // redc.drawText(Integer.toString(mScore), x, y, mScorePaint); // black on top
Because the FILL alone was not seeing any of the Stroke attributes and was coming out very thin.