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?