1

I found this solution to add outline to Custom TextView https://stackoverflow.com/a/16689513/7767664

@Override
public void onDraw(Canvas canvas) {

    Log.i("LOG", "onDraw textView"); // loop

    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); // second call causes infinite loop
    super.onDraw(canvas);
}

it draws ok, but it's looped (onDraw is called infinitely)

loop is caused by calling setTextColor method twice in onDraw, if you call it only once then everything is ok (but you get only one color for text and outline)

how this example can be fixed or what better solution to get the same result?

James Riordan
  • 1,139
  • 1
  • 10
  • 25
user924
  • 8,146
  • 7
  • 57
  • 139

0 Answers0